ASP. NET MVC description Type (ii)

Source: Internet
Author: User

ASP. NET MVC description Type (ii) preface

In the last paragraph of the Controllerdescriptor type of origin process, for the Controllerdescriptor type to say Actiondescriptor type generation is much simpler, this chapter has two topics, The first is the description of the Actiondescriptor type of generation process, the second is to describe the importance of actiondescriptor type, where to reflect its importance? The study of the previous space ignores the execution of the last controller method, and the Actiondescriptor type plays a crucial role in the execution process, see below.

Generation of Actiondescriptor types

Here I have to use the old method ("thief" figure), from the previous space to pull over, quickly explain the actiondescriptor type of generation process.

Figure 1

After the Reflectedcontrollerdescriptor type is generated, the process goes back to the MVC framework, and it calls the Findaction () method under the Controlleractioninvoker type, in Findaction () " is the parameter of the method in the Controlleractioninvoker type, the first parameter type is the controller context type, and the second is the Reflectedcontrollerdescriptor type that we explained in the previous article " Controllerdescriptor type ", the third is the name of the Controller method, the first parameter of the second, in the Findaction () The method is the Findaction () method shown in the Findaction () method in the parameter of the second Reflectedcontrollerdescriptor type, and the parameter is a reference to the upper Findaction () Method is passed down, and then a variable of type MethodInfo is generated by the Actionmethodselector type variable in the Reflectedcontrollerdescriptor type. Used to instantiate the Reflectedactiondescriptor type.

Let's take a look at the definition of the Reflectedactiondescriptor type, example code 1-1

Code 1-1

 Public classReflectedactiondescriptor:actiondescriptor { PublicReflectedactiondescriptor (MethodInfo MethodInfo,stringActionName, Controllerdescriptor controllerdescriptor);  Public Override stringActionName {Get; }  Public OverrideControllerdescriptor Controllerdescriptor {Get; } //        //Summary://Gets or sets the action-method information. //        //return Result://operation-method information.          PublicMethodInfo MethodInfo {Get; }  Public Override stringUniqueId {Get; } //Summary://executes the specified controller context using the specified action-method parameter. //        //Parameters://ControllerContext://The controller context. //        //Parameters://parameters. //        //return Result://The operation return value. //        //Exception://System.ArgumentNullException://the parameters or ControllerContext parameter is null.          Public Override ObjectExecute (ControllerContext ControllerContext, idictionary<string,Object>parameters);  Public Override Object[] GetCustomAttributes (BOOLinherit);  Public Override Object[] GetCustomAttributes (Type attributetype,BOOLinherit);  Public Overrideparameterdescriptor[] GetParameters ();  Public OverrideIcollection<actionselector>getselectors ();  Public Override BOOLIsDefined (Type AttributeType,BOOLinherit); }

In code 1-1, I keep two comments one is the MethodInfo property, and one is the Execute () method, because this property is described in the following importance section.

The importance of the Actiondescriptor type

I must have seen the previous space of friends know that in the ASP. NET MVC Filter (three) We explained the behavior filter in the MVC framework of the specific build execution process, and then in that space because the topic does not match the reason, we ignore the action execution, see 2

Figure 2

For this one who does not understand what the blogger wrote the ASP. NET MVC filter (three), and for this article to illustrate the importance of the Actiondescriptor type need to talk about the execution of the action, the above figure we just need to focus on the part of Figure 3.

Figure 3

The entry for the action execution process is in the Invokeactionmethod () method of the Controlleractioninvoker type, and the method parameters in Figure 3 understand the importance of the Actiondescriptor type. It is necessary to look at 4.

Figure 4

The Actiondescriptor type is abstract, as seen in the previous section, the MVC framework default generation is the reflectedactiondescriptor type, as you can see in Figure 4, The MVC framework first invokes the execute () method of the Actiondescriptor type, except that it is replaced by the implementation type Reflectedactiondescriptor type. It then calls the Getdispatcher () method of the variable of type Actionmethoddispatchercache in the Actiondescriptor type, The Getexecutor () method is then defined by the Actionmethoddispatcher type, and the internal implementation of this method is the MethodInfo information that is disassembled, and the Actionexecutor delegate type is returned, ultimately by the the Execute () method of the Actionmethoddispatcher type "actually executes the Actionexecutor delegate" executes the last action, and returns a value, and then passes the Createactionresult () in the Controlleractioninvoker type refers to an instance of the ActionResult type that was generated by the value of the action execution, and finally in the Invokeactionresult () method, the MVC framework calls the instance Executeresult () method of the ActionResult type to access the view engine.

Jinyuan

Source: http://www.cnblogs.com/jin-yuan/

This article is copyrighted by the author and the blog Park, welcome reprint, but without the consent of the author must retain this statement, and on the article page

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.