Use ASP. NET to develop a three-tier architecture

Source: Internet
Author: User
Deploy a three-tier architecture with ASP. NET

ASP. NET can use the. NET platform to quickly and conveniently deploy a three-tier architecture. The revolutionary change in ASP. NET is that event-based processing is also used on the webpage. You can specify the background code file to be processed, and C #, VB, and J # can be used as the background code language .. NET, and the backend code can conveniently use custom components through naming controls. The display layer is placed on the ASP page, and the database operations and logic layers are implemented by components, which facilitates the implementation of the three-layer architecture.

The following is a small example of creating a message book for the implementation of each layer.

First, create a database GestDB in the sqlserver database, and create a table in GestDB: Guestbook, for example:

Step 1: Open. NET, click File-New-blank solution, select Visal C # project in the pop-up new project, and select ASP as the template.. NET Web applications. name this solution geustbook at the location. as shown in.

Step 2: Create a database access control. Click OK ". In Solution Explorer on the right of the window, right-click solution guestbook and choose add.-> new project. In the following window, select a class library as the template, enter the name and location. Note that this class library theoretically has nothing to do with the message book project, so the storage location can be arbitrary.

Step 3: Create a logic processing layer. In step 2, create another control BusinessLayer. This control is used to call database controls and encapsulate all logic processing in the message book. As shown in

Step 4: reference. Because BUSINESSLAYER uses the WEB control of the system and the DBLayer just created, you must add references to the two. Right-click BUSINESSLAYER's "Reference" and select. NET's "System. web. dll.

Web Layer

The Web layer provides clients with access to applications. This layer is implemented as a Web project in the Duwamish. sln solution file. The Web layer consists of ASP. NET Web forms and hidden code files. Web forms only use HTML to provide user operations, while code hidden files implement event processing for various controls.

Business appearance Layer

The business appearance layer provides an interface for the Web layer to process accounts, category browsing, and book purchases. This layer is implemented as the BusinessFacade project in the Duwamish. sln solution file. The business appearance layer is used as the isolation layer, which isolates the user interface from the implementation of various business functions. Except for low-level systems and support functions, all calls to the database server are performed through this assembly.

Business Rule Layer

The business rule layer is implemented as the BusinessRules project in the Duwamish. sln solution file. It contains the implementation of various business rules and logic. Business Rules complete tasks such as verifying customer accounts and book orders.

Data access layer

The data access layer provides data services for the business rule layer. This layer is implemented as the DataAccess project in the Duwamish. sln solution file.

Sample Code:

The following is a sample code for two different processing paths:

Get product catalog

The presentation layer calls the business appearance layer:

ProductSystem = new ProductSystem ();

CategorySet = productSystem. GetCategories (categoryID );

The business appearance layer directly calls the data layer:

Public CategoryData GetCategories (int categoryId)
{
If (dsCommand = null)
{
Throw new System. ObjectDisposedException (GetType (). FullName );
}
Return FillCategoryData ("GetCategories", "@ CategoryId", categoryId );
}

Add order

The presentation layer calls the business appearance layer:

Public void AddOrder ()
{
ApplicationAssert. CheckCondition (cartOrderData! = Null, "Order requires data", ApplicationAssert. LineNumber );
ApplicationLog. WriteTrace ("Duwamish7.Web. Cart. AddOrder: \ r \ nCustomerId:" +
CartOrderData. Tables [OrderData. CUSTOMER_TABLE]. Rows [0] [OrderData. PKID_FIELD]. ToString ());
CartOrderData = (new OrderSystem (). AddOrder (cartOrderData );
}

The business appearance layer calls the business rule layer:

Public OrderData AddOrder (OrderData order)
{
ApplicationAssert. CheckCondition (order! = Null, "Order is required", ApplicationAssert. LineNumber );

(New BusinessRules. Order (). InsertOrder (order );
Return order;
}

The business rule layer calls the data layer:

Public bool InsertOrder (OrderData order)
{
// The complex processing logic is omitted here
If (isValid)
{
Using (DataAccess. Orders ordersDataAccess = new DataAccess. Orders ())
{
Return (ordersDataAccess. InsertOrderDetail (order)> 0;
}
}
Else
Return false;
}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.