How to: Create a Business 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. |
Business modules are distinct Composite UI Application Block application deployment units that contain business logic elements.
The Smart Client Development Package includes the Visual Studio template named Add Business 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 two classes: Module and ModuleController. 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 ModuleController class contains empty methods that you can modify to customize the behavior of the module on startup. For example, you can add services or display user interface items. 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.
Prerequisites
The Business Module template unfolds a class library project. It requires that you have an existing smart client solution open in Visual Studio.
Note
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 business modules that target older .NET Framework versions with this release of the Smart Client Software Factory.
Steps
You unfold the Business Module template to create a new business module, which is a Composite UI Application Block module.
To create a business module with the Business 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 AddBusiness Module, as shown in Figure 1.
Figure 1
The Add Business Module recipe menu
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 software factory module project templates
Click OK. The recipe starts the Add Business Module wizard. Figure 3 illustrates the first page of the wizard.
Figure 3
The Add Business Module wizard
(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.
Outcome
You will have the following elements in your solution:
- A class library project. This is the module class library. It contains a module initialization class and the module WorkItemController.
- (Optional) A class library project that contains the public interface. This is a project that you can use to define the public interface (for example, constants and services) that you want to share with other modules.
- (Optional) A test project for the module. This is an empty project that you can use to create your unit tests.
- An updated profile catalog. The module definition will be added to the <modules> section of the ProfileCatalog.xml file of the Shell project. The Composite Web Application Block uses this information to load the module when the application starts.
Figure 4 illustrates a smart client solution with a business module named BusinessModule1.
Figure 4
Smart client solution with business module BusinessModule1
Implementation Notes
If you created the business module with a separate interface assembly, the CreateBusinessModule recipe will create constants classes in the implementation assembly that inherit constants classes of the interface assembly. However, if you do not create a separate interface project, the CreateBusinessModule recipe will create constants classes that inherit constants classes of Infrastructure.Interface project.
Next Steps
The following are typical tasks that you perform after you create a business module:
Implement and register global services in the module controller. To do this, follow these steps:
- Add a new class to your project, and then implement it. This will be the service implementation.
- In the ModuleController class, implement the AddServices method. Call the WorkItem.Services.Add method or WorkItem.Services.AddNew method to register your service as a module service, or call the WorkItem.RootWorkItem.Services.Add method or WorkItem.RootWorkItem.Services.AddNew method to register your service as a global service.
- Optionally, you can use the [Service] attribute to register your service as a global service instead of registering it in the AddServices method of your ModuleController class.
For more information about registering services, see Adding Services.
Add menu items in the module controller. To do this, implement the ExtendMenu method in the ModuleController class. You can obtain a reference to the shell 's main menu by using the following code.
WorkItem.UIExtensionSites[UIExtensionSiteNames.MainMenu]
For more information, see Showing UIElements.
Add new items to the tool strip in the shell in the module controller. To do this, implement the ExtendToolStrip method in the ModuleController class. You can obtain a reference to the shell's main toolbar by using the following code.
WorkItem.UIExtensionSites[UIExtensionSiteNames.MainToolbar]
Add views with presenters. You can add views using the Add View (with Presenter) recipe. For information about how to run the recipe, see How to: Add a View with a Presenter.
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.