在PRISM MEF中使用RegisterBootstrapperProvidedTypes时,ImportCardinalityMismatchException

邮箱

当我重写RegisterBootstrapperProvidedTypes并尝试注册自己的WCServiceAgent时,Bootstrapper会抛出一个

ImportCardinalityMismatchException
Additional information: No exports were found that match the constraint: 
ContractName    Microsoft.Practices.ServiceLocation.IServiceLocator
RequiredTypeIdentity    Microsoft.Practices.ServiceLocation.IServiceLocator

发生以下异常:

 protected override void RegisterBootstrapperProvidedTypes()
    {
        this.Container.ComposeExportedValue<IModuleCatalog>(this.ModuleCatalog);
        this.Container.ComposeExportedValue<AggregateCatalog>(this.AggregateCatalog);
    }

还有

    protected override void RegisterBootstrapperProvidedTypes()
    {
         this.Container.ComposeExportedValue<MyWCFServiceAgent>(new MyWCFServiceAgent(1));
    }

在我的引导程序类中

public class Bootstrapper : MefBootstrapper
{
    //protected override void RegisterBootstrapperProvidedTypes()
    //{
    //see above code
    //}

    protected override System.Windows.DependencyObject CreateShell()
    {
        return this.Container.GetExportedValue<ShellWindow>();
    }
    protected override void ConfigureAggregateCatalog()
    {
        this.AggregateCatalog.Catalogs.Add(new AssemblyCatalog(typeof(Bootstrapper).Assembly));
        base.ConfigureAggregateCatalog();
    }
    protected override Microsoft.Practices.Prism.Regions.IRegionBehaviorFactory ConfigureDefaultRegionBehaviors()
    {
        var factory = base.ConfigureDefaultRegionBehaviors();
        //factory.AddIfMissing("AutoPopulateExportedViewsBehavior", typeof(AutoPopulateExportedViewsBehavior));
        return factory;
    }
    protected override IModuleCatalog CreateModuleCatalog()
    {
        return base.CreateModuleCatalog();
    }
    protected override void InitializeShell()
    {
        base.InitializeShell();
        App.Current.MainWindow = (Window)this.Shell;
        App.Current.MainWindow.Show();
    }
}

我怎样才能解决这个问题?造成异常的原因是什么?

动力类

您需要先调用基本实现。

protected override void RegisterBootstrapperProvidedTypes()
{
    base.RegisterBootstrapperProvidedTypes();

    // your custom registrations go here...        
}

如果您看一下bootstrapper基类实现,您将看到需要组成4个导出:

this.Container.ComposeExportedValue<ILoggerFacade>(this.Logger);
this.Container.ComposeExportedValue<IModuleCatalog>(this.ModuleCatalog);
this.Container.ComposeExportedValue<IServiceLocator>(new MefServiceLocatorAdapter(this.Container));
this.Container.ComposeExportedValue<AggregateCatalog>(this.AggregateCatalog);

本文收集自互联网,转载请注明来源。

如有侵权,请联系[email protected] 删除。

编辑于
0

我来说两句

0条评论
登录后参与评论

相关文章

来自分类Dev

如何在Prism中使用MEF检索/导入对象

来自分类Dev

是否可以使用MEF RegistrationBuilder创建PRISM ModuleExport?

来自分类Dev

WPF + PRISM + MEF初始化DownloadedPartCatalogCollection

来自分类Dev

WPF GUI对象共享(PRISM / MEF)

来自分类Dev

使用Prism IEventAggregator跨平台

来自分类Dev

在GraphPad Prism中使用R样式数据

来自分类Dev

触发CompositeCommand时提高InteractionRequests(WPF / PRISM)

来自分类Dev

使用Prism JS的标记未显示

来自分类Dev

使用Prism.js防止自动换行

来自分类Dev

MEF,Prism和导航上的新视图实例

来自分类Dev

WPF中使用DataTemplate / CustomControl的PRISM 6区域

来自分类Dev

如何在MVVM中使用Prism框架自动单击按钮?

来自分类Dev

如何在 Xamarin Forms 的 Prism 中使用 EventToCommandBehavior 获取 ItemTappedEventArgs

来自分类Dev

在 Xamarin Forms 中使用 Prism 在 ContentPages 之间导航维护 NavigationParameters

来自分类Dev

使用Prism时如何传递和接收Sender事件参数?

来自分类Dev

使用嵌套视图时,Prism 7引发异常

来自分类Dev

使用Prism时,哪个组件负责配置容器?

来自分类Dev

使用Prism和Unity容器时的激活错误

来自分类Dev

使用 Prism for Xamarin.Forms 创建新项目时出错

来自分类Dev

Prism和IEventAggregator:加载模块时遇到问题

来自分类Dev

Prism.js仅在开始时突出显示

来自分类Dev

对iOS Xamarin表单执行远程构建时,Prism Navigation错误

来自分类Dev

Prism和IEventAggregator:加载模块时出现问题

来自分类Dev

Xamarin Forms 和 Prism,调用 NavigationPage 时出错

来自分类Dev

DI-使用参数解析实例(DryIoc使用Prism)

来自分类Dev

无法使用Prism从回调方法内部导航

来自分类Dev

在WinRT MVVM中,使用Prism如何监听SetProperty通知?

来自分类Dev

如何使用Prism和Unity实施“先查看模型”?

来自分类Dev

在响应式UI上使用Prism v5

Related 相关文章

  1. 1

    如何在Prism中使用MEF检索/导入对象

  2. 2

    是否可以使用MEF RegistrationBuilder创建PRISM ModuleExport?

  3. 3

    WPF + PRISM + MEF初始化DownloadedPartCatalogCollection

  4. 4

    WPF GUI对象共享(PRISM / MEF)

  5. 5

    使用Prism IEventAggregator跨平台

  6. 6

    在GraphPad Prism中使用R样式数据

  7. 7

    触发CompositeCommand时提高InteractionRequests(WPF / PRISM)

  8. 8

    使用Prism JS的标记未显示

  9. 9

    使用Prism.js防止自动换行

  10. 10

    MEF,Prism和导航上的新视图实例

  11. 11

    WPF中使用DataTemplate / CustomControl的PRISM 6区域

  12. 12

    如何在MVVM中使用Prism框架自动单击按钮?

  13. 13

    如何在 Xamarin Forms 的 Prism 中使用 EventToCommandBehavior 获取 ItemTappedEventArgs

  14. 14

    在 Xamarin Forms 中使用 Prism 在 ContentPages 之间导航维护 NavigationParameters

  15. 15

    使用Prism时如何传递和接收Sender事件参数?

  16. 16

    使用嵌套视图时,Prism 7引发异常

  17. 17

    使用Prism时,哪个组件负责配置容器?

  18. 18

    使用Prism和Unity容器时的激活错误

  19. 19

    使用 Prism for Xamarin.Forms 创建新项目时出错

  20. 20

    Prism和IEventAggregator:加载模块时遇到问题

  21. 21

    Prism.js仅在开始时突出显示

  22. 22

    对iOS Xamarin表单执行远程构建时,Prism Navigation错误

  23. 23

    Prism和IEventAggregator:加载模块时出现问题

  24. 24

    Xamarin Forms 和 Prism,调用 NavigationPage 时出错

  25. 25

    DI-使用参数解析实例(DryIoc使用Prism)

  26. 26

    无法使用Prism从回调方法内部导航

  27. 27

    在WinRT MVVM中,使用Prism如何监听SetProperty通知?

  28. 28

    如何使用Prism和Unity实施“先查看模型”?

  29. 29

    在响应式UI上使用Prism v5

热门标签

归档