Summary after learning "Mini ASP. net mvc Framework"

Source: Internet
Author: User

The second major achievement of reading Teacher Jiang's MVC book is reading this mini ASP. net mvc framework, although it is far inferior to true ASP. net mvc (hereinafter referred to as "MVC") is so complicated and huge, but it is awkward to bypass it in the mini version. I have read this part several times and have not fully understood the structure in it. However, it is essential to thoroughly understand the entire MVC Framework and understand the entire mini MVC framework, without the Mini as the basis, I don't know what to do when I look at the complete framework. Although the entire framework is complex, I think the entire framework can be viewed from a hierarchical perspective and reduced to zero, so the difficulty is reduced.

First, the server processes common Http requests and then sends an Http Response to the browser. The simplest browser sends a request to the index.htm page. The server reads the content of the index.htm file and then sends the content to the browser for response last night. This is simply the binding of a URL to a physical file. The routing mechanism is added to ASP. NET to separate the URL from the physical file. One important part of MVC is the routing mechanism, and the whole request response process becomes

That is, after receiving a request, use the IhttpModule interface to intercept the request. After the URL is analyzed according to the routing rules and the corresponding route is matched, use an instance of the class implementing the IHttpHandler interface to perform corresponding processing. After processing, return HttpResponse to the browser. This is the top layer of the MVC framework. Here we haven't seen the Route, Controller, and Action that we usually use MVC. If there is a link between the two interfaces, the Route is mainly used in the HttpModule section, and the Controller and Action are used in the HttpHandler section. If the big framework has been set, you can refine it. You can view the entire process from HttpModule and HttpHandler respectively.

IHttpModule

IHttpHandler

MvcHandler implements this interface. In the HttpModule section, the routing object has been processed. The rest of MVC calls the behavior methods in the controller, passes in parameters, and binds relevant models, after processing, an ActionResult is returned, and the View content is used as the response message to be displayed in the browser. The processing of MvcHandler is executed in the ProcessRequset method. The detailed process is as follows. First, obtain the Controller name from the input HttpRequestContext. The Controller is obtained through the Controller factory, and the Controller factory is obtained from ControllerBuilder. The Controller executes the Execute method and passes in the RequestContext parameter. The corresponding behavior method will be executed. The process is as follows:

But there are actually more operations included in the Execute method, because you also need to Execute the behavior method, get the parameter from the Route, pass it to the behavior method, and return the ActionResult.

In the Execute method called by ControllBase, a controller context (ControllerContext) is constructed through the incoming request context (RequestContext) and the controller itself, and finally an interface implementing IActionInvoker is called to Execute the behavior method, as shown in

Here, there is an InvokeAction method. The core part of the InvokeAction method is to call the Controller's behavior method through reflection. As for the parameters to be passed in the behavior method, the ParameterInfo instance is generated by calling the IModelBinder interface, the routing parameters are obtained through context, and the reflection mechanism is also used to set values. After the method is called, an instance of the ActionResult abstract class is returned. Then, the ExecuteResult method of the ActionResult is executed to generate the content of the response page. As shown in

The HttpHandler operation is divided into these parts. If they are combined, It is shown as follows:

 

For the HttpModule section, we need to streamline the relationship between several classes.

The whole graph is not actually drawn in the UML format, and I have forgotten it. The purpose of my drawing is to list various classes and Mark calls between classes, for a method, the result is returned from the lead on the left side of the class graph, and the result is passed in from the lead on the right side.

There are still a lot of interfaces used in the entire framework. I think this will give me a decoupling purpose. Instead of calling a method directly through a class, it calls an interface. This eliminates the need to know the details of Access to the called class by the main class.

The above are my study notes for mini MVC. Some garden friends may think that it is good to know more about it. If you have any understanding of the above, please point out. Thank you!

Familiar with the situation, view its structure, understand its nature, and think about its improvements

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.