Class names have been changed to protect the innocent.
If I have an interface named ISomeInterface. I also have classes that inherit the interface, FirstClass
If you want all your code to deal with ISomeInterfaces generically, then yes they should all be disposable.
If not, then the code that creates FirstClass should dispose it:
using (FirstClass foo = new FirstClass()) {
someObjectThatWantsISomeInterface.Act(foo);
}
otherwise, you could always use something like this extension method:
public static void DisposeIfPossible(this object o) {
IDisposable disp = o as IDisposable;
if (disp != null)
disp.Dispose();
}
// ...
someObject.DisposeIfPossible(); // extension method on object
I should also mention that I would prefer a template base class approach to this. I stubbed this out in this blog on building disposable things properly.