1、Lab 5 Creating a Foundational ModuleLab 5: Creating a Foundational ModulePurposeEstimated time to complete this lab: 25 minutes.In this lab, you will use the Smart Client Development guidance package to add a foundational module to you smart client application solution. You will also create a new gl
2、obal service that will simulate a real printing service.After completing this lab, you will be able to: Understand the components of a foundational module Add a new foundational module to a smart client application using the guidance package. Create a global servicePreparationBefore proceeding with
3、this lab, you must install and configure the prerequisite software. For more information, see the topic Start Here.Open the solution for the previous lab (either the one that you created or the end solution for that lab.)Background: Foundational ModulesA foundational module is a module that either p
4、rovides services to the shell and other modules, provides a layout, or both. It does not implement a use case or contain a WorkItem. An example of a foundational module is a module that contains infrastructure services, like caching or logging services. Since a foundational module does not contain a
5、 WorkItem, all the services created within a foundational module are registered as global services with the root WorkItem. Exercise 1: Creating a New Foundational ModuleIn this exercise you create a foundational module which will provide a printing service for all the modules in the application. The
6、 ShippingModule module will consume it to print packing slips and shipping labels for sales orders.Task 1. Use the Guidance Package to add a new Foundational ModuleIn this task you will add a foundation module to your application. The guidance package includes the Visual Studio template named Add Fo
7、undational Module (C#). This template unfolds a new class library project for the module. 1. In Solution Explorer, right-click the Source solution folder, point to Smart Client Software Factory, and then click Add Foundational Module (C#). The Add New Project dialog box appears with the Add Foundati
8、onal Module (C#) template selected.2. Enter PrintingModule as the Name and set the Location to the Source folder of the solution. Click OK. The guidance package displays the Add Foundational Module wizard.Figure 1Add Foundational Module Wizard3. Deselect the option Create an interface library for th
9、is module. If you select this option, the recipe will create an additional project to contain the elements that provide the public interface to the assembly. For more information about separating the interface from the implementation of modules, see the Module Interface Separation pattern in the Sma
10、rt Client Software Factory documentation.4. Deselect the option Create a unit test project for this module. If you select this option, the recipe will create a test project for the module with test classes for your module components. In this lab you will not write unit tests for the module.5. Option
11、ally, select the option Show documentation after recipe completes if you want to see a summary of the recipe actions and suggested next steps after the recipe completes.6. Click Finish. The guidance package will generate a new class library project named PrintingModule.Figure 2 PrintingModule module
12、 in Solution ExplorerThe root folder of the project contains a class, Module. 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 project also contains the following folders: Constant
13、s. This folder contains four classes named CommandNames, EventTopicNames, UIExtensionSiteNames, and WorkspaceNames. You can modify these classes to define module-specific identifiers for your commands, event topics, UIExtensionSites, and WorkSpaces. Services. You use this folder to store the impleme
14、ntation of global services.The recipe also adds the following XML entry for the module to the profile catalog of the application (defined in the file ShellProfileCatalog.xml). This means that the Composite UI Application Block will load the module at application initialization time.XML The Composite
15、 UI Application Block loads modules in the order they are specified in the profile catalog file, unless you explicitly define inter-module dependencies. Thus, the ShippingModule module will be loaded before the PrintingModule. This might lead to problems if the ShippingModule instantiates a service
16、during module initialization that has a dependency in a component that belongs to the PrintingService module. To avoid this problem, you can specify module dependencies by arranging modules into sections and establishing dependencies between the sections. When you create a smart client solution, two
17、 sections are defined by default: Services. Include in this section modules that expose global services to other modules. Typically you will include foundational modules in this section. Apps. Include in this section modules that might have dependencies on services published by other modules. Typica
18、lly you will include business modules in this section.In the next step you will move the PrintingModule module to the Services section so that the Composite UI Application Block loads it before the ShippingModule module.7. Move the element for the PrintingModule module into the Services section, as
19、shown in the following code.XMLSolutionProfile xmlns= Note: You can also define dependencies for a particular module in code using the ModuleDependency attribute. For more information, see Creating a Module in the Smart Client Software Factory help.Task 2. Move Business Entities to Infrastructure.In
20、terface projectIn the next task (Task 3) you will add a printing service to the PrintingModule module. This service will simulate the printing of a sales order, thus its methods will receive an Order entity as a parameter. Since the Order class is defined in the ShippingModule project, you would nee
21、d to add a reference to it in the PrintingModule project. To avoid having a reference to the ShippingModule project in the PrintingModule project, in this task you will move the Order and OrderLineItem entities to the Infrastructure.Interface project.8. In Solution Explorer, select the Order.cs and
22、OrderLineItem.cs files in the BusinessEntities folder of the ShippingModule project, cut them, and paste them in the BusinessEntities folder in the Infrastructure.Interface project.Even though you moved the source code files to the Infrastructure.Interface project, the classes namespace is still Adv
23、entureWorks.ShippingModule.BusinessEntities. In the following steps you will rename the namespace to AdventureWorks.Infrastructure.Interface.BusinessEntities.9. Go to the Edit menu, point to Find and Replace and then select Quick Replace.10. Set AdventureWorks.ShippingModule.BusinessEntities in the
24、Find what field.11. Set AdventureWorks.Infrastructure.Interface.BusinessEntities in the Replace with field.12. In the Look in drop down list, set Entire Solution. 13. Click Replace All. 13 occurrences should be replaced.Task 3. Implement the printing serviceIn this task you will create a simple prin
25、ting service that will be consumed by the ShipNewOrderView view. 14. In Solution Explorer, right-click the Services folder in the PrintingModule project, point to Add and then click New Item. 15. From the Templates window, select Interface and set the name to IPrintingService.16. Click Add.17. Add t
26、he following using statement to the file. You will use it to refer to the Order and OrderLineItem classes.C#using AdventureWorks.Infrastructure.Interface.BusinessEntities;18. Change the interface signature to make it public:C#public interface IPrintingService19. Add a method named PrintPackingSlip t
27、o the interface body. This method will be used to print the packing slips for an order. C#void PrintPackingSlip(Order order);20. Add a method named PrintShippingLabels to the interface body. This method will be used to print the shipping labes for an order.C#void PrintShippingLabels(Order order);21.
28、 In Solution Explorer, right-click the Services folder in the PrintingModule project, point to Add and then click Class.22. Set the class name to LocalPrintingService and then click Add.23. Add the following using statements at the top of the file:C#using System.Windows.Forms;using AdventureWorks.In
29、frastructure.Interface.BusinessEntities;24. Change the class signature to make it public and to implement the IPrintingService interface:C#public class LocalPrintingService : IPrintingService25. Implement the PrintPackingSlip method. In this method, display a message box as demonstrated in the follo
30、wing code.C#public void PrintPackingSlip(Order order) MessageBox.Show(String.Format(Packing slip for Order # 0 sent to printer., order.OrderId.ToString();26. Implement the PrintShippingLabels method. In this method, display a message box as shown in the following code.C#public void PrintShippingLabels(Order order) MessageBox.Show(String.Format(Shipping labels for Order # 0 sent to printer., order.OrderId.ToString();Task 4. Register the Printing Service as a Global ServiceIn this task, you will register the printing serv
copyright@ 2008-2022 冰豆网网站版权所有
经营许可证编号:鄂ICP备2022015515号-1