Sunday, December 14, 2008

Composite WPF Guidance - Part 10 Modules (Dynamic Loading)

Dynamic Module Loading: In dynamic module loading, modules are discovered at run time, which the shell does not directly reference. The advantage of dynamic module loading is that modules can be added to the application without having to add any new references or modify the executable. The other advantage is that it gives you flexibility as to how modules are discovered; for example, the Composite Application Library ships with support for loading modules by scanning a directory, specifying in configuration, or on demand.
Configuration Driven Module: LoadingIn this style of loading, modules are located by the ConfigurationModuleEnumerator, which scans the App.config file for modules and module dependencies.
protected override IModuleEnumerator GetModuleEnumerator()
{
ConfigurationStore store = new ConfigurationStore();
return new ConfigurationModuleEnumerator(store);
}
App.Config file entries
Directory Driven Module Loading: In this style of loading, modules are located by the DirectoryLookupModuleEnumerator, which scans the assemblies in a directory and locates all the types that implement IModule. It will also look for the ModuleDependency attribute to determine the dependent modules that need to be loaded before loading the current module. protected override IModuleEnumerator GetModuleEnumerator()
{ return new DirectoryLookupModuleEnumerator(@".\"); }

2 comments:

Anonymous said...

would it be possible to add a module after the application has been started. This would be great for debugging, trying out different implementations without restarting the app.

thanks, mbo

Prajeesh Prathap said...

Hi mbo,
You can use the on deman loading of modules in composite WPF guidance for this situation.