简体   繁体   English

WPF + PRISM + MEF初始化DownloadedPartCatalogCollection

[英]WPF+PRISM+MEF initializing DownloadedPartCatalogCollection

I am trying to initialize a module from my MefBootStrapper implementation 我正在尝试从MefBootStrapper实现中初始化模块

Type type = typeof(OrderDetailsModule.OrderDetailsModule);

ModuleInfo mi = new ModuleInfo {
    ModuleName = type.Name,
    Ref = new Uri(type.Assembly.Location, UriKind.RelativeOrAbsolute).AbsoluteUri,
        InitializationMode =InitializationMode.WhenAvailable,
        ModuleType = type.AssemblyQualifiedName
    };

this.ModuleCatalog.AddModule(mi);

I get an error 我得到一个错误

failed to load type for module OrderDetailsModule. 无法加载模块OrderDetailsModule的类型。 \\r\\nError was: Unable to locate the module with type 'OrderDetailsModule.OrderDetailsModule, OrderDetailsModule, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null' among the exported modules. \\ r \\ n错误是:无法在导出的模块中找到类型为'OrderDetailsModule.OrderDetailsModule,OrderDetailsModule,Version = 1.0.0.0,Culture = neutral,PublicKeyToken = null'的模块。 Make sure the module name in the module catalog matches that specified on ModuleExportAttribute for the module type.." 确保模块目录中的模块名称与在ModuleExportAttribute上为模块类型指定的名称匹配。

Digging down Prism, in MefModuleInitializer, there is an if (this.downloadedPartCatalogs.TryGet(moduleInfo, out partCatalog)) and the downloaded parts is empty. 挖掘棱镜,在MefModuleInitializer中,有一个if (this.downloadedPartCatalogs.TryGet(moduleInfo, out partCatalog)) ,并且下载的部件为空。 I can see in the MefModuleInitializer class, downloadedPartCatalogs is injected via the ImportingConstructor attribute. 我可以在MefModuleInitializer类中看到,downloadedPartCatalogs是通过ImportingConstructor属性注入的。

This is my OrderDetailsModule class 这是我的OrderDetailsModule类

[Export("OrderDetailsModule")]
public class OrderDetailsModule
{
}

Question is, where do i export the downloadedPartCatalogs? 问题是,我在哪里导出downloadedPartCatalog?

Your module class must implement the IModule interface and be attributed with the ModuleExportAttribute. 您的模块类必须实现IModule接口,并具有ModuleExportAttribute属性。

[ModuleExport(typeof(ModuleD))]
public class ModuleD : IModule 
{...}

Or use the AssemblyCatalog to automatically to discover and load modules. 或使用AssemblyCatalog自动发现和加载模块。

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

    this.AggregateCatalog.Catalogs.Add(new AssemblyCatalog(typeof(ModuleA).Assembly));
    this.AggregateCatalog.Catalogs.Add(new AssemblyCatalog(typeof(ModuleC).Assembly));
    . . .
}

Please read the Prism documentation: https://github.com/PrismLibrary/Prism/blob/master/Documentation/WPF/30-ModularApplicationDevelopment.md#modules-in-mef 请阅读棱镜文档: https : //github.com/PrismLibrary/Prism/blob/master/Documentation/WPF/30-ModularApplicationDevelopment.md#modules-in-mef

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM