Prism Learning: Loading a Module from a configuration file

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.