Saturday, May 19, 2007

Creating a Module

Modules are distinct deployment units of a CAB Application.
A module is a .NET assembly that has attributes, and contains classes that the CAB can find and use.
Dependency affects the loading sequence.

To create a module

  1. Create a new class library project or Windows control library project.
  2. Add a reference to Microsoft.Practices.CompositeUI and Microsoft.Practices.ObjectBuilder
  3. Add a ModuleAttribute to the project so that other modules can identify your module.

    Add the following line to the AssemblyInfo.cs file.

    [assembly: Microsoft.Practices.CompositeUI.Module("mainMod")]

To create a module initializer

  1. Create a new public class in the library project.
  2. Modify the class to inherit from the Microsoft.Practices.CompositeUI.ModuleInit class.
  3. If you want to add services programmatically to the module, override the AddServices method of the ModuleInit class.
  4. If you want to display the user-interface or perform custom logic on startup, override the Load method of the ModuleInit class.

To add dependencies to the module

  1. Either in the ModuleInit class or in the AssemblyInfo file, add module dependencies as shown in the following code.
    [assembly: Microsoft.Practices.CompositeUI.ModuleDependency("TheModuleYouDependOn")]

To load modules when the application starts, you must use a catalog file to list the modules to load. The default name for this file is ProfileCatalog.xml.

To load a module

  1. Add a new XML file to the main project named ProfileCatalog.xml.
  2. Edit the contents of ProfileCatalog.xml to list the appropriate modules to load as shown in the following code.








No comments: