asp.net mvc three important descriptive objects: Controllerdescriptor and Actiondescriptor

Source: Internet
Author: User
Tags definition bool

The creation of Controllerdescriptor and Actiondescriptor

Whether the controllerdescriptor used to describe controller, or the actiondescriptor used to describe the action method, have two versions of synchronous and asynchronous, then these different types of Under what circumstances did Controllerdescriptor's actiondescriptor be created?

First, Controlleractioninvoker and Asynccontrolleractioninvoker

Controllerdescriptor's creation was designed to an important component called Actioninvoker, which, as the name suggests, Actioninvoker specifically for the execution of the action method. We will give an in-depth introduction to Actioninvoker in the 7th chapter of this book, "Action Method Execution", where we only need to make a simple understanding of it.

Actioninvoker implements the Iactioninvoker interface with the following definition, the only way to implement the execution of the specified action method, while the controller of the default base class for controller has a A Actioninvoker property that represents the Actioninvoker that is actually used to define the execution of all the action methods in the controller type.

   1:public Interface Iactioninvoker
2: {
3: bool Invokeaction (ControllerContext ControllerContext, string actionname);
4:}
5:
6:public Abstract class Controller
7: {
8: //other Members
9: Public iactioninvoker Actioninvoker {get; set;}
10:}

The System.Web.Mvc.Async.IAsyncActionInvoker interface, which has the following definition, is an asynchronous version of Actioninvoker. Iasyncactioninvoker inherits the Iactioninvoker interface and, on this basis, defines two begininvokeaction/endinvokeaction methods for asynchronous execution of the action method.

   1:public Interface Iasyncactioninvoker:iactioninvoker
2: {
3: IAsyncResult begininvokeaction (controllercontext controllercontext, string ActionName, AsyncCallback Callback, object state);
4: bool Endinvokeaction (IAsyncResult asyncresult);
5:}

asp.net mvc is really actioninvoker for action method synchronous and asynchronous execution, respectively, Controlleractioninvoker and Asynccontrolleractioninvoker. As shown in the following code snippet, Controlleractioninvoker defines a protected method getcontrollerdescriptor used to obtain the corresponding controller context based on the specified Controllerdescriptor, its subclass Asynccontrolleractioninvoker overrides this method.

   1:public class Controlleractioninvoker:iactioninvoker
2: {
3: //other Members
4: protected Virtual Controllerdescriptor getcontrollerdescriptor (ControllerContext controllercontext);
5:}
6:
7:public class Asynccontrolleractioninvoker:controlleractioninvoker, Iasyncactioninvoker, IActionInvoker
8: {
9: //other Members
Ten: protected override Controllerdescriptor Getcontrollerdescriptor (ControllerContext controllercontext);
11:}

All we want to know is which type of actioninvoker is used by default (no explicit setting of the controller type's Actioninvoker property). asp.net MVC's selection mechanism for the type of actioninvoker used in Conroller is this:

Obtains the registered Actioninvoker through the current dependencyresolver with the Iasyncactioninvoker interface, and as the default Actioninvoker if the returned object is not NULL.

Obtains the registered Actioninvoker through the current dependencyresolver with the Iactioninvoker interface, and as the default Actioninvoker if the returned object is not NULL.

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.