我正在使用Prism
v4 并MEF
与Telerik RadDocking
. 为了使用这些停靠面板Prism
并与这些面板一起使用,需要一个自定义适配器。MEF
我有一个工作适配器,其导出如下:
[Export]
public class RadPaneGroupRegionAdapter : RegionAdapterBase<RadPaneGroup>
{
[ImportingConstructor]
public RadPaneGroupRegionAdapter(IRegionBehaviorFactory regionBehaviorFactory)
: base(regionBehaviorFactory)
{
}
...
}
我在引导程序中配置聚合目录,如下所示:
protected override void ConfigureAggregateCatalog()
{
this.AggregateCatalog.Catalogs.Add(new AssemblyCatalog(typeof(Bootstrapper).Assembly));
this.AggregateCatalog.Catalogs.Add(new DirectoryCatalog("Modules"));
this.AggregateCatalog.Catalogs.Add(new AssemblyCatalog(typeof(ViewModelLocator).Assembly));
this.AggregateCatalog.Catalogs.Add(new AssemblyCatalog(typeof(MyContractClass).Assembly));
}
棱镜抱怨多次出口?
问题是,当我尝试将此适配器添加到Prism
适配器映射时,我收到ImportCardinalityMismatchException,告诉我“找到多个与约束匹配的导出:xxx.Adapters.RadPaneGroupRegionAdapter”
protected override RegionAdapterMappings ConfigureRegionAdapterMappings()
{
RegionAdapterMappings mappings = base.ConfigureRegionAdapterMappings();
mappings.RegisterMapping(typeof(RadPaneGroup),
this.Container.GetExportedValue<Adapters.RadPaneGroupRegionAdapter>());
return mappings;
}
我无法理解为什么会发生这种情况。适配器类与 bootstrapper 在同一个程序集中,所以我希望只有一个匹配的导出。
请帮忙!
更新:
如果我注释掉这一行,则永远不会抛出异常:
this.AggregateCatalog.Catalogs.Add(new AssemblyCatalog(typeof(MyContractClass).Assembly));
也许问题在于它MyContractClass
依赖于相同的Telerik
控件?如果是这种情况,我将如何解决这种歧义?