Adding an instance to a MEF container

*爱你&永不变心* 提交于 2019-12-09 14:41:44

问题


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!