Unity to dispose of object

Posted by Johan Levin on Stack Overflow See other posts from Stack Overflow or by Johan Levin
Published on 2009-09-18T09:41:08Z Indexed on 2010/06/18 3:53 UTC
Read the original article Hit count: 376

Is there a way to make Unit dispose property-injected objects as part of the Teardown?

The background is that I am working on an application that uses ASP.NET MVC 2, Unity and WCF. We have written our own MVC controller factory that uses unity to instantiate the controller and WCF proxies are injected using the [Dependency] attribute on public properties of the controller. At the end of the page life cycle the ReleaseController method of the controller factory is called and we call IUnityContainer.Teardown(theMvcController). At that point the controller is disposed as expected but I also need to dispose the injected wcf-proxies. (Actually I need to call Close and/or Abort on them and not Dispose but that is a later problem.)

I could of course override the controllers' Dispose methods and clean up the proxies there, but I don't want the controllers to have to know about the lifecycles of the injected interfaces or even that they refer to WCF proxies.

If I need to write code myself for this - what would be the best extension point? I'd appreciate any pointer.

© Stack Overflow or respective owner

Related posts about unity

Related posts about ioc-container