ASP. net mvc description type (2), asp. netmvc

Source: Internet
Author: User

ASP. net mvc description type (2), asp. netmvc
ASP. net mvc description type (2) Preface

In the last article, we will talk about the Origin process of the ControllerDescriptor type. For the ControllerDescriptor type, generating the ActionDescriptor type is much simpler. There are two topics in this chapter, the first is to explain the generation process of the ActionDescriptor type, and the second is to describe the importance of the ActionDescriptor type. Where does it reflect its importance? The execution process of the final controller method is ignored for the previous study, and the ActionDescriptor type plays a crucial role in the execution process. Let's take a look at the following.

 

Generation of ActionDescriptor type

Here I want to use the old method ("Stealing" diagram) to pull it from the previous section to quickly describe the generation PROCESS OF THE ActionDescriptor type.

Figure 1

After the ReflectedControllerDescriptor type is generated, the process will return to the MVC framework, and the FindAction () method under the ControllerActionInvoker type will be called, in the FindAction () the first parameter type is the Controller context type, and the second parameter is the ReflectedControllerDescriptor type we described in the previous article [ControllerDescriptor type ], the third parameter is the name of the Controller method. The first parameter is temporarily ignored. In the FindAction () method, the FindAction () parameter in the second ReflectedControllerDescriptor type is used () method [FindAction () method shown in the figure], and the parameter is passed by referencing the FindAction () method of the upper layer, and then passed through ReflectedCon The ActionMethodSelector type variable in the trollerDescriptor type generates a MethodInfo type variable for instantiating the ReflectedActionDescriptor type.

Let's take a look at the definition of the ReflectedActionDescriptor type, sample code 1-1

Code 1-1

Public class descriptor: ActionDescriptor {public Descriptor (MethodInfo methodInfo, string actionName, ControllerDescriptor controllerDescriptor); public override string ActionName {get;} public override ControllerDescriptor {get ;} //// Summary: // obtain or set operation-method information. //// Return result: // operation-method information. Public MethodInfo {get;} public override string UniqueId {get;} // Abstract: // use the specified operation-method parameter to execute the specified controller context. //// Parameter: // controllerContext: // controller context. //// Parameters: // parameter. //// Return result: // return value of the operation. //// Exception: // System. ArgumentNullException: // The parameter parameters or controllerContext is null. Public override object Execute (ControllerContext controllerContext, IDictionary <string, object> parameters); public override object [] GetCustomAttributes (bool inherit); public override object [] GetCustomAttributes (Type butattri, bool inherit); public override ParameterDescriptor [] GetParameters (); public override ICollection <ActionSelector> GetSelectors (); public override bool IsDefined (Type attributeType, bool inherit );}

In code 1-1, I keep two Annotations: one is the MethodInfo attribute, and the other is the Execute () method, because this attribute is described in the importance section below.

 

Importance of the ActionDescriptor type

All the friends who have read the previous sections know that ASP. net mvc filter (3) We explained the specific generation and execution process of the behavior filter in the MVC framework, and then the reason for the inconsistency of the topic in that section, we ignored the execution of Action. See figure 2.

Figure 2

If you have any questions about this image, you can view the ASP file written by the blogger. net mvc filter (3), and for this article to illustrate the importance of the ActionDescriptor type, we need to talk about the Action execution process. The above figure only needs to focus on the part of Figure 3.

Figure 3

The entry to the Action execution process is in the InvokeActionMethod () method of the ControllerActionInvoker type. The method parameters in Figure 3 understand the importance of the ActionDescriptor type. It is required.

Figure 4

The ActionDescriptor type is abstract and can be seen in the previous section. By default, the MVC framework is generatedReflectedActionDescriptorType. As shown in figure 4, the MVC Framework calls the Execute () method of the ActionDescriptor type at the beginning, but the implementation typeReflectedActionDescriptorType is replaced, and thenActionMethodDispatcherCacheThe GetDispatcher () method of the type variable is then defined by the GetExecutor () method in the ActionMethodDispatcher type. The internal implementation of this method is the MethodInfo information of the disassembly, And the return is the ActionExecutor delegate type, finalActionMethodDispatcherExecute () method of the type [actually executed is the ActionExecutor Delegate] executes the final Action, returns a value, and thenControllerActionInvokerIn the type, CreateActionResult () references the instance whose value has just been executed to generate the ActionResult type. Finally, in the implementation of the InvokeActionResult () method, the MVC Framework calls the instance ExecuteResult () of the ActionResult type () method to access the View engine.

 

 

Author: Jin Yuan

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

The copyright of this article is shared by the author and the blog Park. You are welcome to reprint this article. However, you must keep this statement without the author's consent and go to the Article Page.


How does the VIEW layer of ASPNET MVC2 receive strong data?

In ASP. NET MVC2, there are three ways for the Controller to pass data to the View.
 
How to reference a strong type in the ASPNET MVC2 User Control

User Control? You mean PartialView?
ViewUserControl <ModelClass>

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.