Because the former is mainly to do webfrom development, MVC development and not too deep understanding. Since coming to the new team at the Innovation Workshop, the technology has been used without prior exposure, such as MVC and EF, and WCF, which has always been a big pressure. In the case of many problems are not clear, ask the people around, others just to tell themselves a ballpark. And the first two days because asked a relatively fine question, but also by other people's sentence hit. "I can only tell you the method, you also expect me to hand over to you, do not you have to learn ah ... ”。 There is no way to find the time to find some information in the following study.
After a preliminary understanding of MVC, many people find that MVC and three-tier architecture development concept will be very confusing, so the two days of study notes to organize and share to their classmates. At the same time also do a small demo, so that no contact with the MVC development of the classmate, can have a simple understanding of MVC.
One, the difference between MVC and the three-tier architecture
① What is a three-tier architecture?
In school, when discussing MVC with classmates or teachers, others might say, "It's a three-tier architecture!" The entity layer (Model), the entity used to create the object, the business Logic layer (BLL), which is used to deal with the relationship between complex data or between business relationships; the database access layer (DAL), which is used to access the database, and of course, the view layer, which is used to display the data; In fact, although they know that it is not so, but they are only a little bit of understanding, but also explained not clear, so also forget. (The relationship between the operations of the specific three-tier architecture can be seen in my previous blog "ASP." NET development ". NET three-tier architecture simple parsing).
The relationship between them is basically as follows:
Also remember the summer vacation in Zhengzhou to find an internship work, was asked a concept of an n-layer architecture, at that time on the ignorant, no one has heard of it! However, later query data know that the so-called N once architecture is based on the needs of the system to the business Logic layer (BLL) or database access Layer (DAL) to abstract into several layers (specifically, then abstract into classes), to facilitate the processing of logic and code module maintenance. The rationale is still based on a three-tier architecture.
② What is MVC?
MVC is actually a model of software architecture, which is what we often call design patterns. It consists of three modules, which are shown in the MVC name: Model, view, controller;
The models and Views (view) Here are completely different from the models and Views (view) in the three-tier architecture.
1) The model in MVC refers to the data model that encapsulates the data associated with the business logic of the application, in addition to encapsulating the processing of the data (the equivalent of business logic). This is a model layer that is completely different from the three-tier architecture.
Features of the model in MVC:
① has the right to direct data access, such as: access to the database;
The ② model does not depend on Views and controllers (Controller), i.e. the model does not care how it is displayed or how it is manipulated;
Changes in the data in the ③ model are generally "advertised" through a refresh mechanism;
④ in order to implement the view in ③ that the "mechanism" used to monitor this model must be registered on this model beforehand. Thus, the view can understand the changes that have occurred on the data model.
2) View, where the view is basically the same as the view in the three layer, is to display the data, there is no logic on the program. In order to refresh the data on the view, the view needs to access the model it monitors, so it should be registered with the data it is monitoring.
3) Controller, This concept is a concept that does not exist in the three layer. It primarily acts on different levels of organization, and is used to control the flow of applications. Deal mainly with events and make corresponding. "Events" mainly include: User behavior and data changes.
The above is a conceptual distinction between the three-tier architecture and MVC.
Second, the difference between the operating mechanism of WebForm website and MVC website
Operating mechanism of ①webform website
Let's say we're going to visit a WebForm site now: www.google.com.hk/Default.aspx (just an example). What are the actions our browsers and servers do?
1) First, the browser will send the request message to the destination server.
IIS is configured to know that the Web site is mounted on the server and that we access the Web site by accessing the virtual directory. At this time, the destination host IIS receives a request to access the Default.aspx file under the virtual directory, which is also a very complex process, including requesting a DNS server, locating the destination host IP, and accessing the destination host based on the IP address. Complex network process is not described, interested in their own to find information learning);
2) When the server-side IIS software receives the request, the request is handed over to the. NET framwork for processing;
3). NET Framwork creates an object of the Default_aspx class, which is what we call the Page object. (after the Webfrom site is created and compiled Default.aspx will be compiled into Default_aspx class)
The entire process is still an HTTP request, and the internal mechanism of IIS implements an IHttpHandler interface that implements a Processrequestfang method
This is what MSDN explains.
The ProcessRequest () method will call the Page_Load () method of the corresponding page
1 protected void Page_Load (object sender, EventArgs e) 2 {3 //Processed business logic or a code to access the database 4 //HTML or other content to output 5 }
4) return to browser (including HTML,CSS,JS, etc.)
The process is as follows:
Operating mechanism of ②MVC website
Let's say we're going to visit an MVC site now: Www.google.com.hk/FirstPage/Default (just an example). What are our browsers and servers doing?
1) The browser sends request message (Firstpage/default) to the server
2) server-side IIS corresponding request requests
3). NET framwork resolves the URL based on the routing configuration, creates an object of the FirstPage class, and invokes the corresponding default method
1 public ActionResult Default () 2 {3 4 return view ();//Return to view 5 }
4) then access the default.cshtml under the View folder and return it to the browser (which includes HTML,CSS,JS, etc.)
The process is as follows:
This is just a relatively simple process to run. In fact, in the process of a lot of things, such as: Execute Global.asax in the Application_Start () method to complete some initialization work, and so on, will continue to parse in future articles.
The above is the difference between the WebForm website and the MVC website operating mechanism.
So what are the advantages of using MVC more than WebForm?
① The most important thing is. NET programmers will no longer use the Microsoft-encapsulated controls that many people have criticized for their development.
The ②MVC design pattern reduces the coupling between the model, the business and the data, and the view. The idea of using a three-tier architecture for the development of WebForm sites is also to reduce the coupling of data and views;
③ can reuse views, meaning that the same data can be displayed using different views with different icons.
Parsing the differences between ASP. NET WebForm and MVC development