Good day! I have this question. Suppose I have a class that implements the IDisposable interface. This class has a managed resource that also implements this interface. Here is the minimum code for my class.
class MyClass : IDisposable { private SomeContext _context = new SomeContext(); public void Dispose() { if(_context != null) _context.Dispose(); } } And then I had a question. How correct is this implementation? More precisely, how wrong is it and how does it threaten? (wherever I looked I saw a more complex implementation of the Dispose pattern). It seems that there is only one IDisposable field (it is assumed that it correctly implements this pattern in its internals), and in order to release the resource correctly, it is sufficient to simply call the Dispose method for the _context field at the right time. What am I wrong? Is such a simple implementation applicable to the practitioner and why is it generally bad?