ControllerDescriptor, ActionDescriptor, ParameterDescriptor

Source: Internet
Author: User

ControllerDescriptor, ActionDescriptor, ParameterDescriptor

Model binding occurs when the Action method is bound to a parameter. The metadata required for this binding parameter process comes from the Controller. The behavior method and parameter descriptor ContrllerDescriptor, ActionDescriptor, and ParameterDescriptor. The following is a class chart, which adds some classes mentioned in the book to the graph of instructor Jiang.

The three descriptors are divided into the upper and lower parts. The figure below shows the relationship between the Descriptor and the top part is added by me, it is the Info class and Attribute feature class used by each Descriptor during use. The following is mainly about introducers, while others are about flower arrangement.

ControllerDescriptor: Used to describe the Controller for metadata. It contains the Controller name ControllerName (obtained by URL) and its Type. The ICustomAttribute interface can be used to obtain the Attribute feature of the Controller and determine whether a given feature is used for the current Controller, in particular, Filter filtering. However, because this is an abstract class, the returned feature arrays are empty.

ReflectedControllerDescriptor: It is the inheritance of ControllerDescriptor. The book says it is the only inheritance,However, there is another ReflectedAsyncDescriptor that inherits the ControllerDescriptor class. I don't know how to reconcile it. If any park friends know the reason, please answer the question.Override all abstract methods of the base class ControllerDescriptor, so that the obtained feature array is no longer an empty array. Because reflection is used to obtain the Attribute, the ReflectedControllerDescriptor is displayed in the name.

ReflectedAsyncControllerDescriptor: An asynchronous version of the role, which also inherits the ControllerDescriptor directly and records the AsyncController of the asynchronous Controller. The FindAction and GetConnonActions definitions are different from those of ReflectedControllerDescriptor. The former returns an empty array, the following method is used with the XXXAsync/XXXCompleted naming method.

Flower arrangement:

  • FindAction obtains the ActionDescriptor by matching the Action name or ActionName attribute using the reflection method name;
  • ActionNameAttribute is similar to ActionMethodSelectorAttribute. The latter is used for test and determination when the Action method is executed. The two are used in the same way, but they are used in different scenarios. Both HttpGetAttribute, HttpPostAttribute, and AcceptVerbsAttribute inherit ActionMethodSelectorAttribute. However, HttpPostAttribute internally calls AcceptVerbsAttribute;
  • If the method in a Controller does not want to be an Action method, you can use NonActionAttribute;

ActionDescriptor: Used to describe the metadata information of the Action method. ActionName and ControllerDescriptor implement ICustomerAttribute, get the method GetParameters () at the next level, and have their own methods for Action: 1) ActionName; 2) GetSelectors () returns an empty array, 3) GetFilters () returns the classes of four Filter sets, 4) Excute ()

AsyncActionDescriptor: Inherits ActionDescriptor, but it is also an abstract class and overwrites Excute. Because this is an asynchronous class, Excuete is a synchronous method and cannot execute a synchronous method, so I overwrote this method and asked it to throw an exception during execution. He defined the BeginExcute/EndExcute method, which is a sign of the Asynchronous Method of APM.

ReflectedActionDescriptor: Inherits the objects returned by GetAction of ActionDescriptor and ReflectedControllerDescriptor, and overwrites all abstract methods of the base class. In the same case, ReflectedActionDescriptor and ReflectedControllerDescriptor are named after reflection,

ReflectedAsyncActionDescriptor: Inherits AsyncActionDescriptor, which is provided by AsyncControllerDescriptor. Because it is a non-abstract class, it overwrites the abstract method of the AsyncActionDescriptor base class. An AsyncControllerDescriptor object indicates a bunch of XXXAsync, however, it can only describe the actions in AcyncController.

TaskAsyncActionDescriptor: Another Asynchronous Method, but unlike ReflectedAsyncActionDescriptor, TaskAsyncActionDescriptor can describe the Action method in a common Controller. The BeginExcute/EndExcute method is defined inside the class.

ParameterDescriptor: The sum of Model bindings. Like ControllerDescriptor and ActionDescriptor, The ICustomer interface is implemented and the interface method is implemented for it. However, like them, the returned result can only be an empty array. However, the BindingInfo in controls the behavior of Binding Request data to parameters.

ReflectedParameterDescriptor: Inherits ParameterDescriptor and has the same name attribute of the ParameterInfo type.

Insert: The BindINfo of ParameterDescriptor returns the ParameterBindingInfo object. The ModelBinder object returned by the Binder attribute is the core of Model binding. The other three attributes are derived from BindAttribute. The IsPropertyAllowed of BindAttribute indicates whether binding is allowed.




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.