Multiple Modules in Same Assembly + MEF

Topics: Prism v4 - Silverlight 4, Prism v4 - WPF 4
Jul 18, 2010 at 1:47 PM

Creating more than one module class (using ModuleExport) in the assembly (good for simple deployment as default implementation in core modules) and configuring only one module to be loaded (from the app.config) causes all modules to be resolved by MEF. Even if the module doesn’t appears in the app.config.

1. What if I want to load only one module in an assembly contains more than one module? I think that there should be an option to choose the specific module to load from the configuration file and not the all assembly types.

2. It seems to be more reasonable to have modules when using unity instead of MEF for resolving and registering types such as services (at least in current Prism/MEF modularity version). Part of the module job is to register types that may be consumed later. Loading module using MEF is pointless in current version, since having exports in the same assembly causes MEF to load each on demand (for example having an import elsewhere). I think that part of the module functionality is to decide what type to export, hence I think that there should be a way exporting types as module load.

 

 

[Export]
class Service : IService
{
}

[ModuleExport(typeof(Module))]
class Module : IModule
{
    public void Initialize()
    {
        // TODO : Register exports with MEF here so only registered export could be imported.
    }
}

Tomer

Jul 20, 2010 at 10:44 PM

Have you looked at loading modules on demand either in config or in the ModuleExport attribute on the modules you do not wanted loaded when the assembly is discovered?