The Web API refers to the ASP. This section describes Web-based API systems that are hosted in IIS.
This section mainly covers the global configuration of the Web API. It is how to gracefully implement this configuration. MVC has been known to initialize the global file. The Web API is essentially an ASP. NET applications. So it is also a globalconfiguration static class in the global definition. The function of this class is to initialize the ASP. Applications. Below is the definition of globalconfiguration.
//
//Summary:
// provides global for ASP. System.Web.Http.HttpConfiguration.
public static class Globalconfiguration
{
public static httpconfiguration Configuration {get;}
public static Httpmessagehandler DefaultHandler {get;}
//
//summary:
// get global System.Web.Http.HttpServer.
//
//Return results:
// Global System.Web.Http.HttpServer.
public static httpserver defaultserver {get;}
public static void Configure (Action}
It defines 3 static read-only properties and a method that is a delegate type for developers to initialize the configuration themselves.
- The Configuration read-only property is the Httpconfiguration type. User to define applications. The main definitions are some dependency injection, parameter binding, message format program, routing, filter. Message Formatter, service (note that the service here is not in the development, backstage to the front desk to provide services, but applications for themselves to handle the request of the type of collaboration collection) and so on. We will explain httpconfiguration in detail later.
- DefaultHandler is Httpmessagehandler. The default message handler. We look at Httpmessagehandler learned that is an abstract class, where the default initialization of new Httproutingdispatcher, in fact Httproutingdispatcher is also a message handler, we call the route dispatcher. Its default message processing endpoint, which is based on route matching, if a message handler is found, is located. Otherwise, distributing the request to Httpcontrollerdispatcher is also a message handler, which we call the controller dispatcher. Know the students of WCF, this should be very familiar with. We'll explain the message handlers in more detail later.
- Defaultserver is the Httpserver type. is essentially a message handler. Because Httpserver inherits from Delegatinghandler, and Delegatinghandler inherits from Httpmessagehandler, later chapters will be described in detail.
- Configure (action
Lazy Loading
private static Lazy
Read-Only configuration properties
public static Httpconfiguration Configuration
{
get {return _configuration. Value; }
}
private static lazy{
return new lazy{
httpconfiguration config = new Httpconfiguration (new Hostedhttproutecollection (routetable.routes));
Servicescontainer Services = config. Services;
Contract.assert (Services! = NULL);
Services. Replace (typeof (Iassembliesresolver), New Webhostassembliesresolver ());
Services. Replace (typeof (Ihttpcontrollertyperesolver), New Webhosthttpcontrollertyperesolver ());
Services. Replace (typeof (Ihostbufferpolicyselector), New Webhostbufferpolicyselector ());
Services. Replace (typeof (Iexceptionhandler),
New Webhostexceptionhandler (services. Getexceptionhandler ()));
return config;
});
}
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 httpconfiguration. How is httpconfiguration initialized? What is the default configuration? How do we define our own configuration.
Web API Source Anatomy of the global configuration