Creating an Application Development Framework Using Enterprise Templates, Part 2
In the first part of this article, we looked at different building blocks that provide the core foundation for building the enterprise template. In this part, we will demonstrate how to take the building blocks and convert them into an application development framework that can be used as the starting point for building new .NET applications.
We will split the enterprise template construction process into the following steps:
- Define the application structure that can be saved as an enterprise template
- Create a policy file and associate it with the application structure
- Convert the application structure and the policy file into an enterprise template
- Customize the Visual Studio.NET IDE to enable our template to be available in the New Project dialog box
- Customize the template by adding useful information such as help topics and so on
Before we look at the above steps, we will need to clearly identify the structure and naming scheme for our enterprise template.
Structure and naming scheme for the template
When you are creating an enterprise template, it is very important to determine, in advance, the structure and the naming scheme for our enterprise template. When creating customized enterprise templates, we can use the Enterprise Template Projects (that have the .etp file extension) as the starting point. The following chart provides information on the directory structure as well as the naming standard that we are going to adopt.
Please refer to Part 1 of this article for more information on the different reusable blocks. Now that we have defined the initial application structure and the naming scheme, let us go ahead and create this initial structure using Visual Studio.NET. To accomplish this, we will select File->New Project and then expand Other Projects in the Project Types pane and select theEnterprise Template Projects folder. In the templates pane, we will select Enterprise Template Project, name the project CustomDistributedAppTemplate, and then create the project in the C:\Projects folder, as shown below.
Once the project is created, we then can add the nested enterprise templates (such as UIProjects, WebServiceProjects, BusinessFacadeProjects, BusinessRulesProjects, DataAccessProjects, and SystemFrameworkProjects) to the CustomDistributedAppTemplate project.To perform this, we will select CustomDistributedAppTemplate in the solution explorer and then right-click on it to select Add->New Project. In the New Project dialog box, we will select Enterprise Template Projects in the Project Types pane and Enterprise Template Project in the Templates pane. Now enter UIProjects as the name of the project and click OK. This will create a UIProjects project under CustomDistributedAppTemplate. We will repeat the same process for creating the other projects (changing the project names to WebServiceProjects, BusinessFacadeProjects, BusinessRulesProjects, DataAccessProjects, and SystemFrameworkProjects) as well.
Adding building blocks to enterprise template projects
With the addition of all the nested enterprise templates to the master template, we have completed the creation of an initial application structure. Now, we can add the individual building blocks that we talked about earlier to the template. We will start by adding the Utilities project to the SystemFrameworkProjects project. Before we do this, we will copy the Utilities project folder to the SystemFrameworkProjects folder using Windows Explorer. This is required because this template folder structure will be replicated when new projects are created from the template. Once we copy the folder, we then can add the project to the template by right-clicking on the SystemFrameworkProjects and selecting File->Add Existing Project. In the existing project dialog box, we then select the Utilities.csproj file to add the project.
We will repeat the same process for the other projects such as ExceptionManagement, Encryption, and ConfigurationHandler and add them to the SystemFrameworkProjects template. Similarly, we will add the SqlDataAccess project to the DataAccessProjects template. We also repeat the same process for WebUI and WebService projects by adding them to UIProjects and WebServiceProjects templates respectively.
After adding all of the above projects to the CustomDistributedAppTemplate, the solution explorer should look like the following figure.
Now that we have created the application structure, we need to associate an application policy file with the template.
Associating the policy file with the template
Before we create a policy file for our template, let us understand what a policy file is and how relates to a new language called TDL. Basically, a policy file allows us to control the Visual Studio.NET environment by allowing us to clearly define the configuration settings. Within the policy file, we could do things such as setting compiler options, pointing VS.NET to display custom help topics, restricting project references, and so on. The policy file is described using a language named TDL (Template Description Language), that is based on XML.
For our template, instead of creating a policy file from scratch, we will copy the existing policy file (that is supplied by Microsoft along with VS.NET) and customize it. The procedure to associate a policy file with the template is detailed below.
- Select CustomDistributedAppTemplate from the solution explorer and right-click on it to select Properties from the context menu.
- Click the ... icon that is right next to the Policy file property and select the DAP.tdl file.
- Make a copy of the DAP.tdl file and rename it to CustomDistributedAppTemplate.tdl.
Once we associate a policy file to the template project, we then can easily customize the policy file to our requirements. We will be modifying the contents of the policy file in the later parts of this article.
Page 1 of 4