Services in HttpConfiguration ASP.NET

1.6k Views Asked by At

Can anyone help me understand how services work in HttpConfiguration? What is that they accomplish that Filters and MessageHandlers cannot do? Also, they don't seem to implement any interface. Where are they used in the pipeline?

1

There are 1 best solutions below

0
Ally On

From this link, Configuring ASP.NET Web API 2 it states that:

The Services collection is not a general-purpose mechanism for service discovery or dependency injection. It only stores service types that are known to the Web API framework.

So, for example, it could be used for replacing the default HTTP Controller Selector with a custom one. You could, therefore, create your own controller selector (inherited from DefaultHttpControllerSelector) to dynamically select a Controller and replace the existing service by adding code to the WebApiConfig file.

config.Services.Replace(typeof(IHttpControllerSelector), new MyCustomControllerSelector(config));