Udostępnij za pośrednictwem


How to: Create a Module

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

A module encapsulates a set of related concerns. Modules are independently developed and deployed, and they interact with each other to create the application. For more information about modules, see the Modules technical concept.

This topic describes how to create a module.

Prerequisites

This topic assumes that you already have a solution based on the Composite Application Library. For information about how to do this, see How to: Create a Solution Using the Composite Application Library.

Steps

The following procedure describes how to create a module.

To create a module

  1. Add a new class library project to your solution.

  2. Add references to the following Windows Presentation Foundation (WPF) assemblies:

    • PresentationCore.dll
    • PresentationFramework.dll
    • WindowsBase.dll
  3. Add references to the Composite Application Library assemblies:

    • Microsoft.Practices.Composite.dll
    • Microsoft.Practices.Composite.Wpf.dll
  4. Delete the Class1.cs file.

  5. Add a new class file named {ModuleName}Module.cs to your module project (replace {ModuleName} with your module's name).

  6. Add the following using statement at the top of the file.

    using Microsoft.Practices.Composite.Modularity;
    
  7. Change the class signature to make it public and to implement the IModule interface, as shown in the following code.

    public class MyModuleModule : IModule
    {
    
    }
    
  8. Implement the Initialize method of the IModule interface. In this method, you implement logic to initialize the module. For example, you can register views and services, or add views to regions. The following code, extracted from the Dynamic Modularity QuickStarts, shows an example implementation of the Initialize method.

    public class ModuleC : IModule
    {
        private readonly IRegionManager _regionManager;
    
        public ModuleC(IRegionManager regionManager)
        {
            _regionManager = regionManager;
        }
    
        public void Initialize()
        {
            _regionManager.Regions["MainRegion"].Add(new DefaultViewC());
        }
    }
    

    Note

    For more information about how to register services, see to How to: Register and Use Services.
    For more information about how to add views, see How to: Show a View in a Shell Region.

  9. Consider adding folders to organize the project. The following are common folders that you add to your module:

    • Views. In this folder, you store views implementations.
    • Services. In this folder, you store service implementations and service interfaces.
    • Controllers. In this folder, you store controllers.
  10. Configure the module so that it gets loaded when the application starts, or on demand. You can load modules statically or dynamically. Consider the following:

    • When you load a module statically, the Shell contains a direct reference to the module's assembly. For more information about statically loading an assembly, see How to: Statically Load Modules.
    • When you load a module dynamically, the Shell does not contain a reference to the module's assembly. Instead, the module is discovered when the application starts and it is loaded dynamically. For more information about dynamically loading a module, see How to: Dynamically Load Modules.

Outcome

You will have a new module in your solution.

Next Steps

The following are typical tasks that you perform after you create a module:

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.