Web API Source Profiling default configuration (httpconfiguration)

Source: Internet
Author: User

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

    1. routing Table (Routes)
    2. Filter (Filters)
    3. Default Message Handler (Messagehandlers)
    4. Property Dictionary (properties)
    5. Dependency Injection Decoupling (dependencyresolver)
    6. Error handling policy (includeerrordetailpolicy)
    7. Services (services, where the service is the interface and implementation for the services of the Web ApI framework)
    8. Media Format Program (formatters)
    9. 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:

    1. Jsonmediatypeformatter: The corresponding is used to handle the request header is Application/json or Text/json format,
    2. Xmlmediatypeformatter: Corresponds to the application/xml format that is used to process the request header
    3. Formurlencodedmediatypeformatter: The corresponding is used to handle the request header is application/x-www-form-urlencoded,
    4. 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)

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.