How to: Create a Foundational Module

Retired Content

This content is outdated and is no longer being maintained. It is provided as a courtesy for individuals who are still using these technologies.
This page may contain URLs that were valid when originally published, but now link to sites or pages that no longer exist.
To create client business applications using current Microsoft technologies, see patterns & practices' Prism.

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.

The Foundational Module template unfolds a class library project. It requires that you have an existing smart client solution open in Visual Studio.

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

  1. Using Visual Studio, open an existing smart client solution.
  2. 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.


    Figure 1

    The Add Foundational Module recipe menu
  3. 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.


    Figure 2

    The Add Foundational Module project templates in the Add New Project dialog
  4. Click OK. The recipe starts the Add Foundational Module wizard. Figure 3 illustrates the first page of the wizard.


    Figure 3

    The Add Business Module recipe wizard
  5. (Optional) If you want to create a separate project that contains the layout logic, select the This module provides a layout view check box.
  6. (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.)
  7. (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.


Figure 4

Smart client solution with foundational module FoundationalModule1
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:
    1. Add a new class for the service to your project.
    2. Add the logic for the service to the class.
    3. Add the [Service] attribute to your class to register it as a global service.
    4. 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.