Multi-layer architecture in ASP. NET and ASP. NET

Source: Internet
Author: User

Multi-layer architecture in ASP. NET and ASP. NET

Many people feel certain difficulties in developing multi-layer applications. Let's look at an example: for a small company with only one or two people, one person may take on many jobs at the same time, such as the boss, cashier, accounting, marketing, sales, and development. For a large company, there will be a strict division of labor. Each person only completes a part of the work and must cooperate with each other to ensure normal operation. The previous development program is similar to a small company. All functions, such as user interface and database access, are completed in one page. The following disadvantages are:

1. Difficult to develop, making it difficult to achieve collaborative development by multiple people

2. Once the database or rules change, you may need to re-Modify the entire page to increase maintenance costs.

3. Because all functions are mixed together, program reusability is poor. If you develop a new project, you almost need to rewrite the code.

To solve this problem, people have proposed the concept of "multi-layer applications", which is essentially similar to a large company with clear authority and division of pages, place data access, business rules, and other functions in specialized files. Popular architectures include layer-2 architecture, three-layer architecture, and MVC.

I. l2 Architecture

A layer-2 architecture divides a program into a user interface layer and a data access layer. In essence, the database access code is put into the data access layer, and the user interface layer operates the database through the data access layer. The interaction relationships are as follows: ("<--->" indicates a bidirectional arrow)

User Interface <---> Data Access <---> Database

Ii. layer-3 Architecture

The layer-3 architecture separates the business logic in the layer-2 architecture from the data access layer to form a separate business logic layer. After the program is divided into three layers, the data access layer only performs database operations, while the business logic layer is responsible for various data processing.
The top layer includes four components: DAL (data processing layer), BLL (business logic layer), UI (user interface layer), and Model (entity Model ). The first three are the layer-3 structure that people often say.
1) database access layer (DAL): it is also known as the persistent layer. Its function is mainly to access the database. Simply put, Select, Insert, Update, and Delete operations on data tables are implemented. If you want to add an ORM element, it will include mapping between the object and the data table, and object Object persistence;
2) business logic layer (BLL): it is the core of the entire system and is related to the business (domain) of the system;
3) user interface layer (UIA): it is the UI part of the system and is responsible for user interaction with the entire system. In this layer, the ideal state should not include the business logic of the system. The logic code in the presentation layer is only related to the interface elements;
4) Entity Model layer (Model): contains all the data information, which exists in the form of various Entity instances. Is the basic level of the system;

Figure 1. Three-tier architecture


The perfect three-tier structure should be: Modify the presentation layer without modifying the logic layer. Modify the logic layer 2 without modifying the data access layer. To a certain extent.

The three-tier architecture mainly makes the project structure clearer and the division of labor clearer, which is conducive to later maintenance and upgrade. It solves the problem of code encapsulation at different stages in each business operation process of the entire application, and enables programmers to focus more on the business logic of a certain stage. However, performance may not be improved, because when the subprogram module is not executed, the main program module can only be in the waiting state. This shows that dividing an application into layers will cause some loss in its execution speed. However, from the perspective of team development efficiency, we can feel a big difference.

It should be noted that although the three-tier architecture has many advantages, if your program is very simple or will not be reused in the future, or you do not have to adopt the two-tier architecture, it may be faster to develop two or more common programs. It should be handled according to the actual situation.

Iii. MVC

M (Model layer) is mainly responsible for business logic and database interaction;
V is the View layer, which is used to display and submit data;
C is the Controller. It is mainly used to capture requests and control request forwarding;

MVC is a number of modules with different functions in the view layer of the application (bsstructure). It is mainly used to solve the style Replacement Problem of the application user interface, separates HTML pages that display data from Business Code as much as possible.

Iv. Differences between layer-3 architecture and MVC

If the difference is true, you can see the following figure:

Figure 2. Differences between MVC and L3 architecture (from http://blog.csdn.net/beijiguangyong/article/details/7029257)


The three-tier architecture consists of the interface layer (UI) business logic layer (BLL) and data access layer (DAL), while MVC is the model layer (M) interface layer (View) and the control layer (Controller), and they do not correspond to each other.
If they need to be matched, the view in MVC corresponding to the UI in the layer-3 architecture is used to display and obtain the interface data; the BLL layer and DAL layer in the three-layer architecture correspond to the Model layer in MVC, which are used to process the data transmitted by the upper layer and the data obtained from the database; the Controller in MVC can be regarded as a part of the UI in a three-tier architecture at most.

V. Three-tier architecture reference relationship

Model layer: no project is referenced;
DAL layer: reference the Model. Read the Assembly in web. config, load the class instance, and return it to BLL for use;
BLL layer: Reference Model, DAL;
UI Layer: Reference Model, BLL;

In resource manager, right-click the project file and add a reference. In the displayed dialog box, select the project tag, select the appropriate class library, and click OK. Then, add using "namespace of reference class" to the project file ".

The project has been referenced, but the specified class library file still cannot be found. Check that:
1. Check whether the referenced project has a syntax error and whether to add the using "namespace" to the header file ";
2. Whether the added class library is public.

Related Article

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.