How to: Populate the Module Catalog from XAML
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.
|This topic assumes that you are familiar with modules. For more information about modules, see the Module technical concept.|
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.
The following procedure describes how to build a XAML-based module catalog.
To build a XAML-based module catalog
- Add a new .xaml file, named ModulesCatalog.xaml, in your Shell project.
- 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.
- 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.
- 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.
- 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.
|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="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://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=220.127.116.11" /> </Modularity:ModuleInfoGroup> <Modularity:ModuleInfoGroup Ref="ModulesWY.Silverlight.xap" InitializationMode="WhenAvailable"> <Modularity:ModuleInfo ModuleName="ModuleY" ModuleType="ModuleY.ModuleY, ModulesWY.Silverlight, Version=18.104.22.168"> <Modularity:ModuleInfo.DependsOn> <sys:String>ModuleW</sys:String> </Modularity:ModuleInfo.DependsOn> </Modularity:ModuleInfo> <Modularity:ModuleInfo ModuleName="ModuleW" ModuleType="ModuleW.ModuleW, ModulesWY.Silverlight, Version=22.214.171.124"> </Modularity:ModuleInfo> </Modularity:ModuleInfoGroup> <!-- Module info without a group --> <Modularity:ModuleInfo Ref="ModuleZ.Silverlight.xap" ModuleName="ModuleZ" ModuleType="ModuleZ.ModuleZ, ModuleZ.Silverlight, Version=126.96.36.199" /> </Modularity:ModuleCatalog>
A module catalog, which contains metadata for all the application's modules, is created and populated from a XAML file.
For information about other ways that you can populate the module catalog, see the following topics:
- How to: Populate the Module Catalog from Code
- How to: Populate the Module Catalog from a Configuration File or a Directory in WPF
For more information related to working with modules, see the following topics:
- How to: Load Modules On Demand
- How to: Define Dependencies Between Modules
- How to: Prepare a Module for Remote Downloading
For a complete list of How-to topics included with the Composite Application Guidance, see Development Activities.