We described the global configuration and initialization in the previous section. In this section, we will expand on the configuration read-only property of the globally configured, which is a type of httpconfiguration. It does some of the most basic work on the Web API for the entire API, such as defining default
- routing Table (Routes)
- Filter (Filters)
- Default Message Handler (Messagehandlers)
- Property Dictionary (properties)
- Dependency Injection Decoupling (dependencyresolver)
- Error handling policy (includeerrordetailpolicy)
- Services (services, where the service is the interface and implementation for the services of the Web ApI framework)
- Media Format Program (formatters)
- The parameter binding rule (Parameterbindingrules).
The above is the configured properties. Next, you will expand on some properties.
Formatters
The default formatter, which is a mediatypeformattercollection type.
4 default formats are defined in the API:
- Jsonmediatypeformatter: The corresponding is used to handle the request header is Application/json or Text/json format,
- Xmlmediatypeformatter: Corresponds to the application/xml format that is used to process the request header
- Formurlencodedmediatypeformatter: The corresponding is used to handle the request header is application/x-www-form-urlencoded,
- Jquerymvcformurlencodedformatter
Services
The default service definition is as follows:
Public defaultservices (httpconfiguration configuration)
{
if (configuration = = null)
{
Throw Error.argumentnull ("configuration");
}
_configuration = Configuration;
//Initialize the dictionary with all known service types, even if the list for this service type is
//Empty , because we'll throw if the developer tries to read or write unsupported types.
setsingle<iactionvaluebinder> (new Defaultactionvaluebinder ());
setsingle<iapiexplorer> (New Apiexplorer ( Configuration));
setsingle<iassembliesresolver> (new Defaultassembliesresolver ());
setsingle<ibodymodelvalidator> (new Defaultbodymodelvalidator ());
setsingle<icontentnegotiator> (new Defaultcontentnegotiator ());
setsingle<idocumentationprovider> (null); Missing
Setmultiple<ifilterprovider> (New Configurationfilterprovider (),
New Actiondescriptorfilterprovider ());
Setsingle<ihostbufferpolicyselector> (NULL);
Setsingle<ihttpactioninvoker> (New Apicontrolleractioninvoker ());
Setsingle<ihttpactionselector> (New Apicontrolleractionselector ());
Setsingle<ihttpcontrolleractivator> (New Defaulthttpcontrolleractivator ());
Setsingle<ihttpcontrollerselector> (new Defaulthttpcontrollerselector (configuration));
Setsingle<ihttpcontrollertyperesolver> (New Defaulthttpcontrollertyperesolver ());
Setsingle<itracemanager> (New Tracemanager ());
Setsingle<itracewriter> (NULL);
This was a priority list. So put the most common binders at the top.
Setmultiple<modelbinderprovider> (New Typeconvertermodelbinderprovider (),
New Typematchmodelbinderprovider (),
New Keyvaluepairmodelbinderprovider (),
New Complexmodeldtomodelbinderprovider (),
New Arraymodelbinderprovider (),
New Dictionarymodelbinderprovider (),
New Collectionmodelbinderprovider (),
New Mutableobjectmodelbinderprovider ());
Setsingle<modelmetadataprovider> (New Dataannotationsmodelmetadataprovider ());
Setmultiple<modelvalidatorprovider> (New Dataannotationsmodelvalidatorprovider (),
New Datamembermodelvalidatorprovider ());
This is a ordered list,so put the most common providers at the top.
Setmultiple<valueproviderfactory> (New Querystringvalueproviderfactory (),
New Routedatavalueproviderfactory ());
Modelvalidatorcache Validatorcache = new Modelvalidatorcache (New lazy<ienumerable<modelvalidatorprovider> > (() = this. Getmodelvalidatorproviders ()));
Setsingle<imodelvalidatorcache> (Validatorcache);
Setsingle<iexceptionhandler> (New Defaultexceptionhandler ());
Setmultiple<iexceptionlogger> ();
_servicetypessingle = new hashset<type> (_defaultservicessingle.keys);
_servicetypesmulti = new hashset<type> (_defaultservicesmulti.keys);
Reset the caches and the known dependency scope
Resetcache ();
}
Default action binding rule: Parameterbindingrules
Parameterbindingrules = Defaultactionvaluebinder.getdefaultparameterbinders ();
interested friends can download the Web Api Source view. http://aspnetwebstack.codeplex.com/wikipage?title=Contributors.
The following will continue to explain the anatomy of httpserver.
Web API Source Profiling default configuration (httpconfiguration)