We have already seen how to load the module from the specified directory, and now we see how to load the module from the application's configuration file. The advantages of loading the Module in this way include: 1. The loaded Module does not need to be referenced in the main program; 2. The configuration file can be modified according to the actual situation without recompiling the program.
The following steps are required:
1. Copy the class library file where the Module resides to the application, either in the same directory as the main program or in a subdirectory under the main program;
2. Overloading the Createmodulecatalog method in Bootstrapper;
3. Modify the application's configuration file
Overloaded Createmodulecatalog method
Add the following code in Bootstrapper.cs:
protected Override Microsoft.Practices.Prism.Modularity.IModuleCatalog Createmodulecatalog () { returnnew configurationmodulecatalog (); }
Modify a configuration file (app. config)
1. Add configsections under the configuration node
< configsections > < name= "Modules" type= " Microsoft.Practices.Prism.Modularity.ModulesConfigurationSection, Microsoft.Practices.Prism.Composition " /> </ configsections >
2. At the synchronization node of the configsections node (also the child node of the configuration), add the Modules node and add the module that will be loaded to the node
< Modules > < assemblyfile= "Modules\hymnal.dll" moduletype= "Hymnal.hymnmodule, hymnal , version=1.0.0.0, Culture=neutral, publickeytoken=null " modulename=" Hymnmodule "/ > </modules>
Description
1. The configsections node must be the first child node under the Configuration node, or the following error will occur:An unhandled exception of type ' System.TypeInitializationException ' is Occurs in PresentationFramework.dll
2. In the module node, theassemblyfile attribute indicates the relative path of the class library file where the module resides; theModuletype property is the Assemblyqualifiedn of the module's type Ame;modulename is the name of Module; These three items are required;
3. If you want the Module to be loaded as needed, you can add the startuploaded= "false" property to it.
Reference URL:
https://msdn.microsoft.com/en-us/library/gg405479 (v=pandp.40). aspx
Prism Learning: Loading a Module from a configuration file