The Managed Extensibility Framework (MEF) in .NET 4 doesn’t support the factory (or dynamic instantiation) approach out of the box.
Example: The LendToWindow class in the BookLibrary sample is a modal dialog. In WPF it’s not possible to reopen a dialog when the user has closed the Window. You need to create a new instance of LendToWindow.
That’s the reason why I use:
in the Export definition of the LendToWindow class. This way I get always a new instance of LendToWindow when I request the ILendToView:
Microsoft has introduced an alternative approach in the MEF implementation for Silverlight. This implementation provides the ExportFactory<T> class. See also:
Unfortunately, this doesn’t work in the .NET 4 MEF implementation. Therefore, I have to register the CompositionContainer and use it in a ServiceLocator fashion.