C# MEF ComposeExportedValue与导出属性

C# MEF ComposeExportedValue与导出属性,c#,dependency-injection,prism,mef,prism-5,C#,Dependency Injection,Prism,Mef,Prism 5,我很难理解为什么我们需要ComposeExportedValue(objval),而不仅仅是使用[Export]属性 我在shell中创建了一个应用程序对象,这个应用程序对象需要注入到prism模块中 public class ShellBootsrapper : MefBootstrapper { [Export(typeof(IMyApplication))] public MyApplication myApp; protected override Depe

我很难理解为什么我们需要ComposeExportedValue(objval),而不仅仅是使用[Export]属性

我在shell中创建了一个应用程序对象,这个应用程序对象需要注入到prism模块中

public class ShellBootsrapper : MefBootstrapper
{

    [Export(typeof(IMyApplication))]
    public MyApplication myApp; 

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

    protected override void ConfigureAggregateCatalog()
    {
       base.ConfigureAggregateCatalog();
       myApp = new MyApplication();
       this.AggregateCatalog.Catalogs.Add(new AssemblyCatalog(System.Reflection.Assembly.GetExecutingAssembly()));
      this.AggregateCatalog.Catalogs.Add(new AssemblyCatalog(typeof(Module1.Module1).Assembly));
}

}
}

我希望[出口]足够了,但显然不行

编辑: 我删除了公共myApp应用程序myApp到shell.xaml.cs(更合理),从bootstrapper开始工作。我总结道;MEF合成正在进行,导出根本不起作用。这就是为什么prism内部库使用ComposeExportedValue(object val)进行导出

受保护的虚拟无效注册表bootstrapperProviderdTypes()
{
this.Container.ComposeExportedValue(this.Logger);
this.Container.ComposeExportedValue(this.ModuleCatalog);
this.Container.ComposeExportedValue(新的MefServiceLocatorAdapter(this.Container));
this.Container.ComposeExportedValue(this.AggregateCatalog);
}

我删除了公共myApp应用程序myApp到shell.xaml.cs(更合理),从bootstrapper开始工作。我总结道;在bootstrapper中,MEF合成正在进行,导出根本不起作用。这就是为什么prism内部库使用ComposeExportedValue(object val)进行导出

受保护的虚拟无效注册表bootstrapperProviderdTypes()
{
this.Container.ComposeExportedValue(this.Logger);
this.Container.ComposeExportedValue(this.ModuleCatalog);
this.Container.ComposeExportedValue(新的MefServiceLocatorAdapter(this.Container));
this.Container.ComposeExportedValue(this.AggregateCatalog);
}

我还发现ComposeExportedValue的目的之一是进行受控出口;i、 e.配置对象、设置属性等,然后将其导出。否则,MEF只会导出一个实例。

我更习惯于将模块注入shell,而不是反过来。您确定要将shell注入模块吗?谢谢您的建议。除了prism模块之外,我还有小型模块化业务应用程序对象。每个prism模块都需要将自己的小型业务应用程序模块/对象注册到位于shell中的主业务应用程序。我发现向Prism模块发送有限的接口(仅用于注册业务对象)更容易。Prism模块通过提供的接口将自己的业务模块注册到主业务应用程序。否则;我必须将所有业务模块导出/发送到shell,这看起来不会使事情变得更简单。
[ModuleExport(typeof(Module1))] 
public class Module1 : IModule
{

    private readonly IRegionManager regionManager;


    [Import]
    private IMyApplication myApp;
protected virtual void RegisterBootstrapperProvidedTypes()
{
    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);
}
protected virtual void RegisterBootstrapperProvidedTypes()
{
    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);
}