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.