Learn asp.net all know its most classic architecture is the three-tier architecture, and is currently the most widely used in a framework. The previous three-tier architecture is known as the MVC architecture, which is used more in HTML development, and now Ajax is mainly used in this architecture. Everyone asp.net three layer refers to the data access layer, the business logic layer and the presentation layer, and all know that the data access layer is used to access data, the business logic layer is used to deal with the business logic of some systems, the presentation layer is to present the content to the user, and user interaction. The advantage of dividing the three layer is that each layer is independent, modifying one layer will not affect the other layer of code, which greatly facilitates the future maintenance and upgrades. Its biggest drawback is that the architecture and coding are complex, and the performance improvement is not helpful, but it may also reduce the efficiency of execution.
Sometimes it really feels like "layer three" is troublesome, in ASP.net 2.0, access to data and display as long as you drag two controls (Accessdatasource/sqldatasource and GridView), a few minutes a page out, But also has the modification in, deletes, the paging, the sorting and so on function. And with a three-tier architecture on a lot of trouble, first to write data access layer code, and then write the business logic layer of the code (to call the data layer method), the last is the presentation layer, that is, the design of the page, as well as the code to invoke business logic to read data. Note: The presentation layer is absolutely not accessing the data layer's content, only through the business layer. The business layer here is the bridge connecting them. So the business layer is the most important layer. So why do you use three floors? One of the major problems mentioned above is that the front and back code is not well separated, is not conducive to division of labor, and second, it is not conducive to future maintenance and upgrades. If it's a personal home page or a small system that someone has done with a single layer, it's pretty good. If it is some of the larger systems, especially enterprise-class applications, it is not to use three or even n-tier. The general three layer is enough, and then dividing more will only increase the difficulty of design and coding.
So how do you go about layering? How does layering conform to the three-tier architecture principle? This is a question that many people who just get started often ask. I have turned over a lot of this case book, but many of them are a layer or two-tier structure, which is three floors. After studying petshop4.0 and some foreign data, I began to learn a little about how to tier. I have summarized the following three types of layered methods:
One: The data tier does not contain any code, only databases, and related stored procedures.
In this mode, the data layer seems to be very simple. Contains only the database you have established, and some stored procedures (note that the stored procedures). In fact, the creation of these stored procedures is also quite complex (I will write a special article in this area), because they can be done in addition to the data access to some other very powerful functions, such as paging, the implementation of search algorithms. The logic of data access is all in the business layer, and the business layer also contains some other logical code. Let's take a look at an example, suppose that there is a table books (book) in the database, a stored procedure getallbooks to read the information of the book, so that a method getbooks () and a public database access class are created in the business layer, getbooks () Open the connection through the database access class, execute the stored procedure, and return the data (the return type can be Datatable,dataset,datareader or entity classes). The business layer is compiled separately into one or several DLL files. Then there is the presentation layer, the presentation layer is bound to the associated control by calling Getbooks () to return the data. The method of the service layer is called at the presentation layer. Generally speaking, book.aspx and Book.aspx.cs are the contents of the presentation layer. All foreground designs, related controls, and data caching are all part of the presentation layer.
Second: The data tier also contains all the public data access codes.
This pattern is not the same as the previous one, mainly to access the data to the data layer. This enables you to support multiple databases in a very good way. The business logic layer calls directly on the data layer's code to access the data, without having to know what the underlying database is. The other is no different from the previous one.
Three: All data reads are placed in the data layer.
The Getbooks () method, as described earlier, is placed at the data layer and a getbooks () method is defined at the business level to be invoked by the presentation layer. In this mode, the business layer does not need to know what the underlying database is, and the structure of the database does not need to be understood. This can be said to be the most standard three-tier architecture, which is used in Microsoft's PetShop 4.0.
The above is my summary of some of the content, may not be very accurate, please give a lot of advice.