How to Establish an ASP. NET three-tier architecture

Source: Internet
Author: User

Web Layer

The web layer provides applications for the client.Program. This layer is implemented as a web project in the duwamish. sln solution file. The web layer consists of ASP. NET web forms andCodeHidden file composition. 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.