带有.Net 4的MEF NonShared对象

时间:2013-04-24 13:51:00

标签: c#-4.0 mef

我想恢复对话开始: MEF - [ImportMany] using ExportFactory<T> in WPF - .NET 4.0

我需要使用Lazy结构创建非共享实例: e.g。

[ImportMany()]
IEnumerable<Lazy<IView, IViewMetadata>> Views{ get; set; }

///// then get views in some method
// [type] is passed to this method 
var instance1 = Views.First(m => m.Metadata.ExportType == type);
var instance2 = Views.First(m => m.Metadata.ExportType == type);

...

似乎没有简单的方法来获取非共享的延迟实例,即使使用属性[PartCreationPolicy(CreationPolicy.NonShared)]

是否有任何样本显示如何解决这个相当常见的任务?

ExportFactory完成了一项工作,但我仍然使用.Net 4.0和MEF 2似乎没有任何推荐版本:http://mef.codeplex.com/releases。将ExportFactory从MEF2提取到.Net 4桌面应用程序的最佳方法是什么?

此问题的任何其他建议或解决方案?

由于

0 个答案:

没有答案