My class is inherited from UnityContainer (from Unity 2.0), here is source code:
public class UnityManager : UnityContainer
{
private UnityManager()
{
_context = new MyDataClassesDataContext();
// ...
}
protected override void Dispose(bool disposing)
{
if ( disposing )
{
_context.Dispose();
}
base.Dispose(disposing);
}
private readonly CMCoreDataClassesDataContext _context;
}
When Dispose method is called for the instance of UnityManager class it drop into recursion… Why? As far as I know base.Dispose should call the Dispose method of base class only… isn’t it? Who call back the Dispose(bool) of UnityManager? How to prevent that?
Thanks.
Thanks to Nicole I’ve found a reason… thanks.
But how to dispose container in this case? In case of call ‘Dispose’ for instance of UnityManager the base.Dispose(true)will call Dispose again…. and again (recursion will start).
To workaround this I’ve added additional private variable bool _bDisposed:
This is a “Dispose” pattern implementation suggested by Bill Wagner in “Effective C#” (If I didn’t any mistake)