码迷,mamicode.com
首页 > 其他好文 > 详细

Adding an instance to a MEF container

时间:2015-06-16 01:13:35      阅读:113      评论:0      收藏:0      [点我收藏+]

标签:

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.

You can use the ComposeExportedValue function for this, like so:

var container = new CompositionContainer();
container..ComposeExportedValue<IConfigFileInvoker>(new ConfigFileInvoker());

container..ComposeExportedValue<IConfigFileInvoker>("export-string",new ConfigFileInvoker());

Adding an instance to a MEF container

标签:

原文地址:http://www.cnblogs.com/zjoch/p/4579603.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!