How to: Statically Load Modules
Retired Content |
---|
This content is outdated and is no longer being maintained. It is provided as a courtesy for individuals who are still using these technologies. This page may contain URLs that were valid when originally published, but now link to sites or pages that no longer exist. |
Overview
This topic describes how to statically load modules. When you load a module statically, the Shell contains a reference to the module's assembly and the types needed from that assembly are directly constructed by the Bootstrapper class. Static module loading provides less decoupling of the Shell with modules than dynamic module loading. However, in cases where decoupling modules from the Shell is not a requirement, loading modules statically can reduce code complexity, simplify the application deployment, improve startup performance, and simplify debugging compared to dynamic loading.
Note
This topic assumes that you are familiar with modules. For more information, see the Module technical concept.
Prerequisites
This topic assumes that you have a solution built with the Composite Application Library that has a module. For information about how to do this, see the following topics:
- How to: Create a Solution Using the Composite Application Library. This topic describes how to create a solution with the Composite Application Library.
- How to: Create a Module. This topic describes how to add a new module to your solution.
Steps
The following procedure describes how to statically load modules.
To load modules statically
Add a reference to the module project in your Shell project.
In your application's bootstrapper class file, add the following using statement at the top of the file. You will use it to refer to modularity elements in the Composite Application Library.
using Microsoft.Practices.Composite.Modularity;
Update the Bootstrapper class of your application to load and initialize modules with the StaticModuleEnumerator class. To do this, you typically override the Bootstrapper class’ GetModuleEnumerator template method. In this method, perform the following tasks:
- Create a new instance of the StaticModuleEnumerator. This class allows you to programmatically register modules.
- Register modules with the StaticModuleEnumerator instance by invoking the AddModule method. The AddModule method takes the following parameters:
- The module initializer class’ type. A module initializer class is a class that implements the IModule interface.
- The names of the modules that the module depends on.
- Return the StaticModuleEnumerator instance. By returning the instance, the base class will register it with the Unity container.
The following code shows the implementation of the GetModuleEnumerator method in the Stock Trader Reference Implementation.
protected override IModuleEnumerator GetModuleEnumerator()
{
return new StaticModuleEnumerator()
.AddModule(typeof(NewsModule))
.AddModule(typeof(MarketModule))
.AddModule(typeof(WatchModule), "MarketModule")
.AddModule(typeof(PositionModule), "MarketModule", "NewsModule");
}
Outcome
The module gets loaded when the application starts.
Retired Content |
---|
This content is outdated and is no longer being maintained. It is provided as a courtesy for individuals who are still using these technologies. This page may contain URLs that were valid when originally published, but now link to sites or pages that no longer exist. |