1
votes

I am trying to initialize a module from my MefBootStrapper implementation

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. \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. Make sure the module name in the module catalog matches that specified on ModuleExportAttribute for the module type.."

Digging down Prism, in MefModuleInitializer, there is an if (this.downloadedPartCatalogs.TryGet(moduleInfo, out partCatalog)) and the downloaded parts is empty. I can see in the MefModuleInitializer class, downloadedPartCatalogs is injected via the ImportingConstructor attribute.

This is my OrderDetailsModule class

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

Question is, where do i export the downloadedPartCatalogs?

1

1 Answers

1
votes

Your module class must implement the IModule interface and be attributed with the ModuleExportAttribute.

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

Or use the AssemblyCatalog to automatically to discover and load modules.

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