Jaa


How to: Populate the Module Catalog from XAML

Overview

This topic describes how to build a XAML-based module catalog for a solution that uses the Composite Application Library. The module catalog contains the metadata for modules and modules groups in the application; it can be populated in different ways and from different sources. For example, it can be populated from a XAML file. An advantage of having a XAML catalog is that declaring object elements in XAML instantiates the corresponding .NET Framework object through its default constructor.

Note

This topic assumes that you are familiar with modules. For more information about modules, 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:

Steps

The following procedure describes how to build a XAML-based module catalog.

To build a XAML-based module catalog

  1. Add a new .xaml file, named ModulesCatalog.xaml, in your Shell project.

  2. The root element of this .xaml file should be a ModuleCatalog instance. In addition to specifying the default namespaces, this root element must also specify the Modularity namespace, as shown in the following code.

    xmlns:Modularity="clr-namespace:Microsoft.Practices.Composite.Modularity;assembly=Microsoft.Practices.Composite"
    
  3. Add a ModuleInfoGroup child element to the ModuleCatalog root element for each module group you have.

    Note

    Putting modules inside module groups is optional. The properties that are set for a group will be applied to all its contained modules. Note that modules can also be registered without being inside a group.

  4. Set the corresponding properties to each ModuleInfoGroup. The properties defined by the ModuleInfoGroup class are the following:

    • Ref. The content of this property indicates the location from where the modules in the module group should be obtained.
    • InitializationMode. This property specifies how all the group modules are going to be initialized. The possible values for this property are: WhenAvailable and OnDemand.
  5. Add ModuleInfo objects to the catalog. ModuleInfo objects can be registered within a group or without a group. Note the following:

    • If you want to register modules in a group, put one ModuleInfo element inside the ModuleInfoGroup tags for each module that the module group contains.
    • If you want to register modules without a group, put the ModuleInfo element inside the ModuleCatalog tags.

    Each ModuleInfo instance has the following properties:

    • ModuleName. This property specifies the logical name of the module.

    • ModuleType. This property specifies the type of the module.

    • Ref. The content of this property indicates the location from where the modules in the module group should be obtained. This property should be set if the module is not inside a module group.

    • InitializationMode. This property specifies how all the group modules are going to be initialized. The possible values for this property are WhenAvailable and OnDemand. The default value is WhenAvailable.

    • DependsOn. This property can be set to a list of the modules names that this module depends on.

      Note

      For more information about setting dependencies between modules, see How to Define Dependencies between Modules.

Note

The module catalog can also be created programmatically, by looking up modules in a specific folder or by reading a configuration file.
For more information about populating a module catalog programmatically, see How to: Populate the Module Catalog from Code.
For more information about populating a module catalog from a directory lookup or from a configuration file in WPF applications, see How to: Populate the Module Catalog from a Configuration File or a Directory in WPF.

The following code shows the XAML-based Module Catalog implementation included in the Remote Modularity QuickStart.

<Modularity:ModuleCatalog xmlns="https://schemas.microsoft.com/winfx/2006/xaml/presentation"
               xmlns:x="https://schemas.microsoft.com/winfx/2006/xaml"
                xmlns:sys="clr-namespace:System;assembly=mscorlib"
               xmlns:Modularity="clr-namespace:Microsoft.Practices.Composite.Modularity;assembly=Microsoft.Practices.Composite">
    <Modularity:ModuleInfoGroup Ref="ModuleX.Silverlight.xap" InitializationMode="OnDemand">
        <Modularity:ModuleInfo ModuleName="ModuleX" ModuleType="ModuleX.ModuleX, ModuleX.Silverlight, Version=1.0.0.0" />
    </Modularity:ModuleInfoGroup>
    <Modularity:ModuleInfoGroup Ref="ModulesWY.Silverlight.xap" InitializationMode="WhenAvailable">
        <Modularity:ModuleInfo ModuleName="ModuleY" ModuleType="ModuleY.ModuleY, ModulesWY.Silverlight, Version=1.0.0.0">
            <Modularity:ModuleInfo.DependsOn>
                <sys:String>ModuleW</sys:String>
            </Modularity:ModuleInfo.DependsOn>
        </Modularity:ModuleInfo>
        <Modularity:ModuleInfo ModuleName="ModuleW" ModuleType="ModuleW.ModuleW, ModulesWY.Silverlight, Version=1.0.0.0">
        </Modularity:ModuleInfo>
    </Modularity:ModuleInfoGroup>
    <!-- Module info without a group -->
    <Modularity:ModuleInfo Ref="ModuleZ.Silverlight.xap" ModuleName="ModuleZ" ModuleType="ModuleZ.ModuleZ, ModuleZ.Silverlight, Version=1.0.0.0" />
</Modularity:ModuleCatalog>

Outcome

A module catalog, which contains metadata for all the application's modules, is created and populated from a XAML file.

More Information

For information about other ways that you can populate the module catalog, see the following topics:

For more information related to working with modules, see the following topics:

For a complete list of How-to topics included with the Composite Application Guidance, see Development Activities.

Home page on MSDN | Community site