This project has moved. For the latest updates, please go here.

Using ReleaseExport without reference to CompositionContainer

Jun 23, 2010 at 9:37 AM

I am using MEF to write a helper class, ViewService, for use in a Silverlight MVVM project.  I import a collection of views (ChildWindow or UserControl) using ImportMany.

For one of the items in the list, is it possible to release and dispose of it after use, then to refer to it again later and have it be re-created?  It uses the  PartCreationPolicy NonShared to make sure a new instance of the view is created to satisfy the import.

Also, to use ReleaseExport I need to have a reference to the CompositionContainer.  I can't seem to find any easy way to get a reference to the composition container from within my class code.  Am I missing something?

Thank you!


Jun 23, 2010 at 9:45 AM

Just found the answer I think!

It looks as though I need to use ExportFactory<T> to manage the lifetime of my object without needing a reference to the CompositionContainer.  Hope this helps someone!