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
- 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.
xmlns:Modularity="clr-namespace:Microsoft.Practices.Composite.Modularity;assembly=Microsoft.Practices.Composite"
- 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.
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=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