![](/img/trans.png)
[英]MEF, why are identical duplicates of one and the same exported plugin created?
[英]Is there a way to tell if MEF created an instance for a type I exported
我的目标是找到我的所有脏模型,当它们退出应用程序时,我应该让它们通知。
我可以通过下面的代码根据类型进入实例,但是问题在于它将为所有视图模型创建实例,因为我只对那些已经由MEF容器创建的实例感兴趣
List<Type> viewModelInterfaces = new List<Type>();
viewModelInterfaces .Add(typeof(IAddressViewModel));
viewModelInterfaces .Add(typeof(ICustomerNameViewModel));
viewModelInterfaces .Add(typeof(IBudgetSummaryViewModel));
foreach (var appInterface in viewModelInterfaces )
{
var obj = Container.GetExports(appInterface, ull,appInterface.FullName).FirstOrDefault();
if (obj != null)
{
var viewModel = obj.Value as IViewModelBase;
if (viewModel != null)
{
if (viewModel.IsDirty)
{
Show Dialog
}
}
}
}
谢谢
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.