问题
How can you add an already created instance to a MEF container/cataloge to use when resolving Imports. I want the functionality that Unity gives with the RegisterInstance
method on its containers.
回答1:
You can use the ComposeExportedValue function for this, like so:
var container = new CompositionContainer();
container.ComposeExportedValue<Application>("Application", Application.Current);
来源:https://stackoverflow.com/questions/5191316/adding-an-instance-to-a-mef-container