In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-03-29 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/03 Report--
This article will explain in detail the example analysis of the multi-tier architecture in ASP.NET. The editor thinks it is very practical, so I share it for you as a reference. I hope you can get something after reading this article.
The multi-tier architecture of Asp.net is mainly to solve the relationship among data layer, logic layer, presentation layer and so on. Here's what I do: first set up a base class for DataCore. The base class encapsulates some basic operations of low-level databases, such as database joins, calling stored procedures, and so on.
Many people find it difficult to develop multi-tier applications. Let's take a look at an example: for a small company with only one or two people, one person may be the boss, cashier, accountant, marketing, sales, development, and so on. For a large company, there will be a relatively strict division of labor, each person only completes part of the work, need to cooperate with each other in order to ensure normal operation. The previous development program was similar to a small company, where all the functions, from the user interface to database access, were done in one page, with the following disadvantages:
1. It is difficult to develop, and it is difficult to realize multi-person collaborative development.
two。 Once the database or rules change, you may have to modify the entire page to increase the cost of maintenance
3. Because all functions are mixed together, the reusability of the program is poor. If you develop a new project, you almost have to rewrite the code.
In order to solve this problem, people put forward the concept of "multi-tier application", which is essentially similar to a large company with clear authority, dividing the pages and putting data access, business rules and other functions in special files. The popular ones are two-tier architecture, three-tier architecture and MVC.
one。 Two-tier architecture
The two-tier architecture divides the program into the user interface layer and the data access layer. Its essence is to put the code that accesses the database into the data access layer, and the user interface layer operates the database through the data access layer. The interaction is as follows: ("" represents a two-way arrow)
User interface data access database
two。 Three-tier architecture
Three-tier architecture, that is, the business logic in the two-tier architecture is separated from the data access layer and becomes a separate business logic layer. After the program is divided into three layers, the data access layer only operates on the database, while the business logic layer is responsible for all kinds of data processing.
From the top layer, it mainly includes four parts: DAL (data processing layer), BLL (business logic layer), UI (user interface layer) and Model (entity model). Among them, the first three are what people often call the three-tier structure.
1) data access layer (database access layer,DAL): sometimes referred to as the persistence layer, its function is mainly responsible for database access. To put it simply, it is to realize the operation of Select,Insert,Update and Delete of the data table. If you want to add the element of ORM, it will include the mapping between the object and the data table, as well as the persistence of the object entity
2) Business logic layer (business logic layer, BLL): it is the core of the whole system, which is related to the business (domain) of the system.
3) presentation layer (user interface layer, UIA): the UI part of the system, which is responsible for the interaction between the user and the whole system. In this layer, the ideal state is that the business logic of the system should not be included. The logical code in the presentation layer, which is only related to interface elements
4) entity model layer (Model): contains all the data information, which exists in the form of various Entity instances. It is the basic level of the whole system.
The perfect three-tier structure should be: modify the presentation layer without modifying the logic layer, and modify the logic layer without modifying the data access layer. Achieve a certain degree of decoupling.
The main purpose of the three-tier architecture is to make the project structure clearer and the division of labor more clear, which is conducive to later maintenance and upgrading. It solves the problem of code encapsulation in different stages of each business operation in the whole application, and makes programmers pay more attention to a certain stage of business logic. However, it may not improve performance, because when the subroutine module is not executed, the main program module can only be in a waiting state. This shows that dividing the application into layers will result in some loss in its execution speed. However, from the perspective of team development efficiency, you can feel a very different effect.
It is important to note that although a three-tier architecture has many benefits, if your program is simple, or certainly will not be reused in the future, or do not necessarily adopt a two-tier architecture, it may be faster to develop a two-tier or ordinary program. It should be dealt with specifically according to the actual situation.
three。 MVC
M is Model (model layer), which is mainly responsible for business logic and database interaction.
V is View (view layer), which is mainly used to display and submit data
C is Controller (controller), which is mainly used to capture requests and control request forwarding
MVC is divided into several modules with different functions in the view layer of the application (BS structure). The main purpose is to solve the problem of style replacement of the application user interface and separate the HTML page that displays the data from the business code as much as possible.
four。 The difference between three-tier structure and MVC
If you make a difference, you can see the picture:
Figure 2. Difference between MVC and three-tier architecture
The three-tier architecture is composed of interface layer (UI), business logic layer (BLL) and data access layer (DAL), while MVC is composed of model layer (M), interface layer (View) and control layer (Controller), and there is no correspondence between them.
If you have to correspond to them, then the UI in the three-tier architecture and the view in the MVC are used to display and obtain the data of the interface; the BLL layer in the three-tier architecture and the Model layer in the DAL layer corresponding to the MVC are used to deal with the data passed by the upper layer and the data obtained from the database; and the Controller in the MVC is at most a part of the UI in the three-tier architecture.
five。 Three-tier architecture reference relationship
Model layer: does not reference any project
DAL layer: reference Model, read assemblies in web.config, load instances of classes, and return them to BLL for use
BLL layer: referencing Model,DAL
UI layer: reference Model, BLL
This is done by right-clicking the project file in Explorer to add a reference. Select the project tab in the pop-up dialog box, select the appropriate class library, and click OK. Then add using "Namespace of reference classes" to the project file.
The project has added a reference, but the specified class library file is still not found. Check:
1. Whether there are syntax errors in the referenced project and whether to add using "namespaces" to the header file
two。 When adding a class library, whether the class library is public.
This is the end of this article on "sample Analysis of Multi-tier Architecture in ASP.NET". I hope the above content can be of some help to you, so that you can learn more knowledge. if you think the article is good, please share it for more people to see.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.