Recursion in Unity and Dispose pattern implementation
Posted
by Budda
on Stack Overflow
See other posts from Stack Overflow
or by Budda
Published on 2010-06-02T16:11:40Z
Indexed on
2010/06/02
16:13 UTC
Read the original article
Hit count: 365
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.
© Stack Overflow or respective owner