Add Business Module Template

The guidance package includes two Visual Studio project templates named BusinessModule.vstemplate (one for C# projects and one for Visual Basic projects). These files can be found under the Templates\Projects\Module.CS and Templates\Projects\Module.VB folders of the WebClientFactoryPackage project. After you register (or install) the guidance package, these templates are available under the Web Client Development October 2007 node in the Add New Project dialog box of Visual Studio. The templates are named Add Business Module (C#) and Add Business Module (Visual Basic), as shown in Figure 1.
Figure 1
Add Business Module templates in Visual Studio.

When you use these templates to create a new module, the recipe framework displays a wizard that you can use to customize the generated code. Figure 2 illustrates the wizard it appears if you selected the Web Client Solution (C#, Web Site) template.
Figure 2
Add Business Module recipe wizard for a Web Site Project solution.

Figure 3 illustrates the wizard as it appears if you selected a Web Application project solution template.
Figure 3
Add Business Module recipe wizard for a Web Application project solution.

Implementation Details

Both Visual Studio template files contain similar XML that provides the connection between the project templates and the recipe framework. In the case of the C# template file, the WizardData element specifies the CreateModuleCS recipe as the recipe that the framework executes when it unfolds the project template.

<Template xmlns=""

You can find the CreateModuleCS definition in the CreateWebClientFactoryModule.xml file (this file is located in the Recipes\CS folder of the WebClientFactoryPackage project).
Some files of the business module are not part of the Add Business Module (C#) and Add Business Module (Visual Basic) templates, such as the Default.aspx file, the Default.aspx.cs file, and the Web.config file, which are placed in the selected Web site. These files are generated from T4 templates. You can use T4 templates to write complex templates with embedded code that gets executed when the template unfolds. The following actions in the CreateModuleCS recipe definition unfold the T4 templates for the mentioned files.

<!-- Generates web.config, default.aspx and default.aspx codebehind and designer codebehind if needed -->
<Action Name="GenerateWebConfig"
<Input Name="Template" RecipeArgument="T4WebConfigPath"/>
<Input Name="ModuleAssemblyName" RecipeArgument="ModuleMainProjectName"/>
<Input Name="ModuleName" RecipeArgument="ModuleName"/>
<Input Name="ModuleFolderNameOnWebSite" RecipeArgument="ModuleFolderNameOnWebSite"/>
<Output Name="Content" />
<Action Name="GenerateDefaultPage"
<Input Name="Template" RecipeArgument="T4DefaultViewPath"/>
<Input Name="ModuleName" RecipeArgument="ModuleName"/>
<Input Name="IsWCSFSolutionWAP" RecipeArgument="IsWCSFSolutionWAP"/>
<Input Name="ModuleWebsiteName" RecipeArgument="ModuleWebsiteName"/>
<Input Name="CreateAsFolderInWebsite" RecipeArgument="CreateAsFolderInWebsite"/>
<Output Name="Content" />
<Action Name="GenerateDefaultCodebehind"
<Input Name="Template" RecipeArgument="T4DefaultViewCodebehindPath"/>
<Input Name="ModuleName" RecipeArgument="ModuleName"/>
<Input Name="ModuleNamespace" RecipeArgument="ModuleNamespace"/>
<Output Name="Content" />
<Action Name="GenerateDefaultDesigner"
<Input Name="Template" RecipeArgument="T4DefaultViewDesignerPath"/>
<Input Name="ModuleName" RecipeArgument="ModuleName"/>
<Output Name="Content" />

For detailed information about T4 templates, see the Guidance Automation Toolkit documentation.

The CreateModuleCS and CreateModuleVB recipes appear as the Add Business Module (C#) and Add Business Module (Visual Basic) commands on the Web Client Factory shortcut menu in Solution Explorer, as shown in Figure 4.
Figure 4
Add Business Module recipe commands.

You use the HostData section in a recipe definition to specify where in the Visual Studio interface the recipe will be shown. In the Recipes\CS\CreateWebClientFactoryModule.xml file, a command bar associated with the WCSFFolder menu is defined in the HostData section. The WCSFFolder menu is displayed when the user right-clicks a solution folder in Solution Explorer.

  <Icon ID="2579" />
  <CommandBar Menu="WCSFFolder" />

The WCSFFolder menu is defined in the file WebClientFactoryPackage.xml located in the root of the WebClientFactoryPackage project.

<Menu Name="WCSFFolder" Text="Web Client Factory" Priority="1">
  <CommandBar Name="Solution Folder"/>

After unfolding the Add Business Module (C#) template, the CreateModuleCS recipe adds references in the generated project to the Composite Web Application Block and Enterprise Library assemblies. To do this, the following actions are executed.

<!-- Add references to CWAB in Module project -->
<Action Name="AddCompositeWebAssemblyReferencesToModule"
  <Input Name="FileNames" RecipeArgument="CompositeWebDlls"/>
  <Input Name="ReferringProject" RecipeArgument="ModuleProject"/>
  <Input Name="AssembliesPath" RecipeArgument="LibraryPathArgument"/>
<!-- Add references to EntLib in Module project -->
<Action Name="AddEnterpriseLibraryAssemblyReferencesToModule"
  <Input Name="FileNames" RecipeArgument="EnterpriseLibraryDlls"/>
  <Input Name="ReferringProject" RecipeArgument="ModuleProject"/>
  <Input Name="AssembliesPath" RecipeArgument="LibraryPathArgument"/>

When you add a business module to a folder in Visual Studio, the project appears in that folder in Solution Explorer. By default, the Location text box in the Add New Project dialog box does not contain the folder in the path. To create the project in that folder on the hard disk, you must update the Location text box to include the folder in the path.

Add Business Module Next Steps


Last edited Nov 12, 2007 at 2:35 PM by siacomuzzi, version 2


No comments yet.