Loading modules from other module, not at Bootstrapper

Topics: Prism v4 - WPF 4
Oct 13, 2011 at 9:49 PM
Edited Oct 13, 2011 at 9:52 PM

I need to create an on-demand module (lets name it ModuleManager) that can load modules from specified directory.

I wrote:

public class ModuleManager : IModule
 {
  [Import]
  AggregateCatalog _aggregateCatalog
  {
   get; set;
  }

  public void Initialize()
  {
   DirectoryCatalog _directoryCatalog = new DirectoryCatalog("Modules");
   this._aggregateCatalog.Catalogs.Add(_directoryCatalog);
  }
 }

I set a breakpoint at the line

this._aggregateCatalog.Catalogs.Add(_directoryCatalog);

and I see the types from the modules placed at "Modules" catalog inside this._aggregateCatalog.Parts property.

But Initialize() methods from those modules are never called and no events from this modules are broadcasted too.

It looks that I don't understand some basic things about module initialization in MEF.

Will be glad to get any help.

 

Oct 14, 2011 at 6:49 AM
Edited Oct 14, 2011 at 6:50 AM

I'm sorry,

I found the reason why MEF do not load modules:

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

should be:

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