Hi, I am registering some wrapers over un-managed objects in container. How can I dispose of them at the end of the container's lifetime? Please bear in mind I have an XML Web service.
A:
As far as I am aware you will have to implement this yourself. I believe Autofac is currently the only .NET container to support this out of the box.
GraemeF
2009-11-09 15:32:16
A:
Most DI Containers have a functionality to dispose of created objects. Typically, a Resolve method has a corresponding method that can dispose of the created object graph.
In Unity, this method is called Teardown.
When your web request is done, you should pass your object graph to the Teardown method to dispose of any IDisposable objects.
Mark Seemann
2009-11-10 08:28:30
I want my container to remain alive as long as it's possible, and I want those disposable objects (that wrap un-managed objects) to get disposed. One of my colleagues told me that, at dispose, the container tries to dispose every disposable registered object. Is that true?
DaeMoohn
2009-11-10 09:16:45
I read some posts that state that the Teardown method is not implemented and is the responsability of an extension to handle the Teardown process.
DaeMoohn
2009-11-10 09:18:33
A cursory look through the Unity source code looks like the Teardown method is implemented. It disposes of all IDisposable objects if appropriate according to their lifetime. You may still need to write a custom lifetime manager if you don't want to use the built-in lifetimes.
Mark Seemann
2009-11-10 09:50:02