This section uses a simple login feature to tell you how to build a three-tier structure.
1. Building a data access layer
(1) Open the VS 2005 development environment and select file → new → project command, 18-3.
(2) In the New Project dialog box that opens, select the project type as "Visual Studio Solution" and select the template as "Blank solution". Then fill in the solution with the name "Mybookshop" and specify the save location, as shown in 18-4.
(3) In Solution Explorer, right-click the solution name and choose Add → new project from the shortcut menu that appears, 18-5.
(4) In the New Project dialog box that opens, select the project type "Visual C #" and select the template as "Class library". The name of the completed project is "Mybookshop.dal", which is used to implement the data access layer. At this point, the project's save location has been entered by default, which is the path generated when the blank solution was just created, as shown in 18-6.
2. Building a business logic access layer
The steps for building a business logic layer are similar to building a data access layer, and the difference is that you need to re-fill in the project name "Mybookshop.bll", as shown in 18-7.
3. Building the presentation layer
(1) In Solution Explorer, right-click on the solution name and choose Add → new Web site from the shortcut menu that appears, as shown in 18-8.
(2) in the Add New Site dialog box that opens, select ASP. NET Web site, select location for file system, and set the path of the Web site, as shown in 18-9.
In three-tier structure development, the model layer is often used. The model layer contains all the entity classes that correspond to the tables in the database. The presentation layer, the business logic layer, and the data access tier layer three pass through the entity objects to achieve the purpose of data passing.
The steps to create the model layer are similar to building the business logic layer and the data access layer, and the difference is that you need to re-fill the project name "Mybookshop.models", as shown in 18-10.
4. Add dependency between tiers
At this point, although the basic framework of the three-tier structure has been successfully built, the layers are independent. You only have to add dependencies to make them work together.
(1) Add the representation layer to the business logic layer and the model layer of dependency. In Solution Explorer, right-click on the presentation layer and choose Add Reference from the shortcut menu that pops up, as shown in 18-12.
(2) In the Add Reference dialog box that opens, select the Projects tab, select the two items with the project name "MYBOOKSHOP.BLL" and "Mybookshop.models", and click the "OK" button, as shown in 18-13.
(3) Use the above method to add a dependency on the data access layer and the model layer in the business logic layer, and the data access layer's dependence on the model layer.
At this point, the dependencies between the three-tier structure and the layers are created.
VS build three-tier architecture (graphic combination)