Mar 1, 2012 at 8:47 PM
Edited Mar 1, 2012 at 8:58 PM
Thanks for your thoughts!
The problem is the second Dispose() call: disposing an already disposed object. Fortunately since it's my class that's in question I can work around like I described.
The class is IDisposable because it handles unmanaged resources that should be cleaned up immediately after they're not needed: that's why I opted not with a simple IDependency. So it's not just a simple class that I want to be garbage-collected early, but
a "true" IDisposable.
Edit for your second post: yeah, that's right, that's what I'm doing.
I disagree with the responsibility of disposing: IMO IDisposables should be properly disposed when they're not used anymore (that's why the usage of the using block is encouraged), thus freeing up all unmanaged resources the class uses. That's not equal
to the life cycle or scope of the object itself, which is managed by the IoC container (and the GC). Since my type here is an ITransientDependency the same instance that's disposed also can't be used elsewhere since all requesting code gets a new instance.
Reading a bit further,
on MSDN it's stated that "If an object's Dispose method is called more than once, the object must ignore all calls after the first one.". That's perfectly reasonable and also answers my question: it looks number one is the way to go.