Recursion in Unity and Dispose pattern implementation
- by Budda
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.