1

我正在尝试使用 Prism、MEF 和 WPF 创建一个非常基本的应用程序。我有一个 WPF 应用程序项目,它有一个 Shell.xaml 和 Bootstrapper。BootStrapper 的代码如下:

public class SimpleMefApplicationBootstrapper : MefBootstrapper
{
    protected override void ConfigureAggregateCatalog()
    {
        //base.ConfigureAggregateCatalog();
        this.AggregateCatalog.Catalogs.Add(new AssemblyCatalog(typeof(SimpleMefApplicationBootstrapper).Assembly));             
        this.AggregateCatalog.Catalogs.Add(new AssemblyCatalog(typeof(PrismApp.Module.Hello.HelloModule).Assembly));
        this.AggregateCatalog.Catalogs.Add(new AssemblyCatalog(typeof(PrismApp.Module.Hello.FinishModule).Assembly));
    }        

    protected override DependencyObject CreateShell()
    {
        return this.Container.GetExportedValue<Shell>();
    }

    protected override void InitializeShell()
    {
        //base.InitializeShell();
        Application.Current.MainWindow = (Window)this.Shell;
    }

    protected override IRegionBehaviorFactory ConfigureDefaultRegionBehaviors()
    {
        var factory = base.ConfigureDefaultRegionBehaviors();           

        return factory;
    }

在解决方案中,我有另一个类库,它有一个视图文件夹、视图模型文件夹和两个模块。这两个模块绑定到两个视图,以便它们可以用作一个区域。如果我尝试从 botstrapper 仅调用一个模块,但当我同时调用两个模块时,它会完美运行。它给了我错误的详细信息,例如:

Loader 发现了一个名为 FinishModule 的重复模块。

我不明白两个模块是否有不同,那么问题出在哪里。我也尝试为这两个模块更改组装,但没有运气。

有任何想法吗?

4

1 回答 1

2

尝试只使用一个电话:

public class SimpleMefApplicationBootstrapper : MefBootstrapper
{
    protected override void ConfigureAggregateCatalog()
    {
        //base.ConfigureAggregateCatalog();
        this.AggregateCatalog.Catalogs.Add(new AssemblyCatalog(typeof(SimpleMefApplicationBootstrapper).Assembly));   

        this.AggregateCatalog.Catalogs.Add(new AssemblyCatalog(typeof(PrismApp.Module.Hello.HelloModule).Assembly));
      //  this.AggregateCatalog.Catalogs.Add(new AssemblyCatalog(typeof(PrismApp.Module.Hello.FinishModule).Assembly));
    }       
于 2013-07-11T09:43:59.947 回答