Releasing ViewModels from Castle Windsor

Topics: Bootstrappers & IoC
Mar 6, 2012 at 12:40 PM

I'm using Castle-Windsor as my container in a Caliburn-Micro Silverlight app. My ViewModel objects are reasonably chunky as they call WCF services and a bunch of other stuff. Therefore, when a window is closed I want to call container.Release(viewModel) so Castle can manage the whole decommission/disposal process, respecting the various lifecycles configured (as outlined in this post).

In my AppBootstrapper I have overridden GetInstance as follows:

protected override object GetInstance(Type serviceType, string key)
if (string.IsNullOrEmpty(key)) return container.Resolve(serviceType);
return container.Resolve(key, serviceType);

But I am struggling to come up with a clean/elegant way of calling container.Release(viewModel). There don't seem to be any hooks available for this.

What is the simplest way of releasing ViewModel objects returned from ViewModelLocator in a Caliburn Micro app?