If I have a SomeDisposableObject
class which implements IDisposable
:
class SomeDisposableObject : IDisposable
{
public void Dis
In general, I think whoever creates the object should be responsible for Disposal. In this case, AContainer creates SomeDisposableObject, so it should be Disposed when AContainer is.
If, for some reason, you think that SomeDisposableObject should live longer than AContainer - I can only think of the following methods:
All in all, though - I'm not really sure the design makes sense. After all, you seem to be expecting client code like:
SomeDisposableObject d;
using (var c = new AContainer()) {
d = c.SomeObject;
}
// do something with d
That seems like broken client code to me. It's violating Law of Demeter, and plain ol' common sense to me.