Here are Todays Amazing Pattern Simpl Deals
More Great Information on Pattern Simpl:
Doing DI with Autofac in ASP.NET Web API (Weblogs @ ASP)
ASP.NET Web API provides a very similar model to MVC for resolving
dependencies using a service locator pattern. What you basically do is to
provide the implementation of that service locator to return any of the
requested dependencies, and that implementation is typically tied to a DI
container.
The service locator can be injected into the Web API runtime using the
ServiceResolver entry in the global configuration object
(GlobalConfiguration.Configuration.ServiceResolver), which basically supports
different overloads.
public void SetResolver(IDependencyResolver resolver);
public void SetResolver(object commonServiceLocator);
public void SetResolver(Func getService, Func
IEnumerable
The first overload receives an instance of a IDependencyResolver
implementation, which provides two methods for resolving one or multiple
dependencies.
public interface IDependencyResolver
{
object GetService(Type serviceType);
IEnumerable
}
GetService should return null if the dependency can not resolved. GetServices
should return an empty IEnumerable if the same thing happens.
The second overload uses reflection for invoking the same two methods,
GetService and GetServices.
The third overload receives a set of Func delegates ...
Weblogs @ ASP