How to: Create a Foundational Module
This content is outdated and is no longer being maintained. It is provided as a courtesy for individuals who are still using these technologies.
A foundational module is a module that either provides services to the shell and other modules, provides a layout, or both. It does not implement a use case or contain a WorkItem.
The Smart Client Development Package includes a Visual Studio template named Add Foundational Module. This template unfolds a new class library project for the module implementation and, optionally, a module interface project. The implementation class library project contains a Module class and, optionally, a view with a presenter (the layout view). The Module class derives from the Composite UI Application Block class ModuleInit. The Composite UI Application Block calls the Load method of this class on startup. The interface class library contains constants definitions and empty folders you can use to store interface elements of the module. For example, you can add service interfaces or constants definitions.
|Note: This template targets.NET Framework 3.5 and ignores the target framework version selected in the New Project dialog box. This means that you cannot create foundational modules that target older .NET Framework versions with this release of the Smart Client Software Factory.|
You unfold the Add Foundational Module template to create a new foundational module, which is a Composite UI Application Block module.
To create a foundational module with the Foundational Module template
- Using Visual Studio, open an existing smart client solution.
- In Solution Explorer, right-click either the solution node or a solution folder, point to Smart Client Factory, and then click AddFoundational Module, as shown in Figure 1.
- The Add New Project dialog box appears. If you want, you can change the Name and Location fields for the project. Figure 2 illustrates this dialog box.
- Click OK. The recipe starts the Add Foundational Module wizard. Figure 3 illustrates the first page of the wizard.
- (Optional) If you want to create a separate project that contains the layout logic, select the This module provides a layout view check box.
- (Optional) If you want to create a separate project that contains the public interface for the module, select the Create an interface library for this module check box. (For more information, see Module Interface Separation.)
- (Optional) If you want a test project for the module to be created with test classes for your module components, select the Create a unit test project for this module check box.
You will have a new class library project with the following project items:
- Module class. This class derives from ModuleInit.
- Constants folder. This folder contains four classes named EventTopicNames, UIExtensionSiteNames, and WorkspaceNames. You can modify these classes to define module-specific identifiers for your commands, event topics, UIExtensionSites, and WorkSpaces.
- Services folder. Use this folder to store the implementation of foundational services.
- If your module provides a layout view, the project will also contain a view named LayoutView and its presenter, the LayoutViewPresenter class.
Figure 4 illustrates a solution that contains a layout view.
Note: When you create a foundational module that provides a layout view, code is added to ModuleInit class to create an instance of the LayoutView and show it on the LayoutWorkspace of the shell.|
Because the LayoutWorkspace in the shell is a DeckWorkspace, the LayoutView of your foundational module will be shown in front of the LayoutView defined in the Infrastructure.Layout project.
Therefore, if your smart client application contains foundational modules with layouts, you have to handle the logic to show each module layout when appropriate.
The following are typical tasks that you perform after you create a foundational module:
Implement and register global services. To do this, follow these steps:
- Add a new class for the service to your project.
- Add the logic for the service to the class.
- Add the [Service] attribute to your class to register it as a global service.
- Alternatively, register your service programmatically in the Module class. To do this, override the AddServices method, and call _rootWorkItem.Services.Add or _rootWorkItem.Services.AddNew to register your service.
For more information about registering services, see Adding Services.
- (Optional) Modify LayoutView for the shell. For example, you can add or remove workspaces, define menu items, and publish or subscribe to events.
Create service agents to consume Web services. Disconnected service agents add offline capabilities to your Web service proxies. This is useful for occasionally connected applications.
For information about how to create a disconnected service agent, see How to: Create a Disconnected Service Agent.