asp.net MVC provides system three with Valueprovider as its core value

Source: Internet
Author: User
Tags abstract static class

Valueproviderfactory

In the ASP.net model binding system, Valueprovider objects that provide data values are created by valueproviderfactory. In the ASP.net MVC application Programming interface, Valueproviderfactory inherits from the Valueproviderfactory class. This article simply describes the Valueproviderfactory-based valueprovider delivery mechanism and how to implement the binding of the data values we need by customizing the valueproviderfactory.

First, Valueproviderfactory

As the following code fragment shows, Valueproviderfactory is an abstract class, and the only abstract method Getvalueprovider used to implement Valueprovider creation based on the specified controller context.

   1:public Abstract class Valueproviderfactory
2: {
3: Public abstract Ivalueprovider getvalueprovider (ControllerContext controllercontext);
4:}

The following list lists the 6 native Valueproviderfactory defined in the model binding system:

Childactionvalueproviderfactory: Creates a Childactionvalueprovider object based on the given controller context.

Formvalueproviderfactory: Creates a Formvalueprovider object based on the given controller context.

Jsonvalueproviderfactory: Converts the request data in JSON form into a dictionary<string, object> object, and eventually creates a Dictionaryvalueprovider <object> objects.

Routedatavalueproviderfactory: Creates a Routedatavalueprovider object based on the given controller context.

Querystringvalueproviderfactory: Creates a Querystringvalueprovider object based on the given controller context.

Httpfilecollectionvalueproviderfactory: Creates a Httpfilecollectionvalueprovider object based on the given controller context.

Ii. Registration of Valueproviderfactory

The registration of valueproviderfactory in the ASP.net MVC application is implemented through static type Valueproviderfactories. As shown in the following code fragment, Valueproviderfactories has a static read-only property factories returns a Valueproviderfactorycollection type representing the Valueproviderfactory collection.

   1:public Static Class Valueproviderfactories
2: {
3: Public static valueproviderfactorycollection factories {get;}
4:}
5:
6:public class Valueproviderfactorycollection:collection<valueproviderfactory>
7: {
8: Public valueproviderfactorycollection ();
9: Public valueproviderfactorycollection (ilist<valueproviderfactory> list);
Public Ivalueprovider Getvalueprovider (ControllerContext controllercontext);
11:}

The Valueproviderfactorycollection Getvalueprovider method returns a Valueprovidercollection object, Each valueprovider in the collection is created by the corresponding valueproviderfactory. The order of Valueproviderfactory in the valueproviderfactorycollection set determines the order in which the Valueprovider is created in Valueprovidercollection, And the order determines the use of precedence.

By default, the Valueproviderfactories factories attribute represents valueproviderfactorycollection containing the 6 kinds of valueproviderfactory we described above, Order (priority) is: Childactionvalueproviderfactory, Formvalueproviderfactory, Jsonvalueproviderfactory, Routedatavalueproviderfactory, Querystringvalueproviderfactory and. If a request with the same name exists in both the request form and the query string, the former is selected.

The Valueprovider-core value delivery system involves three classes of components/types, which are used to implement data value-providing Valueprovider,valueprovider through Valueproviderfactotry, And Valueproviderfactotry is registered through Valueproviderfactotries. The UML shown in Figure 5-4 shows the relationship between the three.

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.