Dynamic module loading in Composite WPF

Topics: Prism v1
Dec 19, 2009 at 1:17 AM

Hi There,

I'm trying to dynamically load a module. By going through the MSDN documents, there are two ways to achieve this, and both need to add some code to Bootstrapper:

either (Using the Directory Lookup Module Enumerator)

protected override IModuleEnumerator GetModuleEnumerator()
{
    return new DirectoryLookupModuleEnumerator(@".\Modules");
}

or (Using the Configuration Module Enumerator)

protected override IModuleEnumerator GetModuleEnumerator()
{
    ConfigurationStore store = new ConfigurationStore();
    return new ConfigurationModuleEnumerator(store);
}

However, I also need to statically load some other modules. Therefore, I have the following in my Bootstrapper:

protected override IModuleEnumerator GetModuleEnumerator()
{
    return new StaticModuleEnumerator().AddModule(typeof(MyModule));
}

How to combine the static and dynamic module loading?

Thanks,

Jie

 

 

 

Dec 22, 2009 at 8:45 PM

Hi Jie,

Is there a particular reason why you need to load some modules statically and the others dynamically? In Prism there is not out of the box way to get this done.

The difference between static and dynamic module loading is that “when you load a module dynamically, the Shell does not contain a reference to the module's assembly; instead, modules are dynamically discovered when the application starts” (from this article).

If you load all modules dynamically you would be gaining the benefit of not having any reference to them from the Shell project. Take into account that “dynamic module loading requires a module's discovering and loading process to be executed on startup that may result in reduced startup performance compared to static module loading. In cases where decoupling modules from the Shell is not a requirement, you should consider static module loading” (also from the article above).

Please let me know if this helps.

Damian Schenkelman
http://blogs.southworks.net/dschenkelman

 

Jan 5, 2010 at 8:43 PM

I understood the pros and cons of the two methods, but didn't know there is no easy way to use both at the same time.

The reason of considering this scenario is to explore alternatives for unit tests with Composite WPF. For example, to statically load product modules, and dynamically load unit test modules, which could minimize the coupling between product code and unit test code, if complete decoupling is not achievable.

Thanks for your reply!

Jie