I'm trying to implement Logout operation in my Silverlight client.
During Login operation, MEF initializes DefaultContainer with instances of the [Export]-ed singleton classes, which contain user-specific information (like password).
Is there a way, to re-initialize/reset/drop MEF infrastructure/DefaultContainer like it was never initialized?
I'd like to navigate to Login page again after user suc开发者_如何学编程cessfully performs Logout operation...
It is not possible to reinitialize the CompositionHost container. Once it has been Initialized or created by default it can't be changed.
You could however create an AggregateCatalog and use a TypeCatalog with the singleton as the only type and remove this from the aggregate when its no longer needed.
This doesn't change the fact that once a 'part' is created by MEF it is available to satisfy any other [Import] which needs it.
From MSDN:
Parts created by the default container to fill imports will be retained by the Managed Extensibility Framework (MEF) until the application shuts down. Long-running applications should use ExportFactory< T > to manage the life cycles of their parts.
精彩评论