October 2012
Intermediate to advanced
504 pages
13h 22m
English
Now that you understand the fundamentals of inversion of control, we can talk about how it works inside of ASP.NET MVC.
The primary way that MVC talks to containers is through an interface created for MVC applications: IDependencyResolver. The interface is defined as follows:
public interface IDependencyResolver
{
object GetService(Type serviceType);
IEnumerable<object> GetServices(Type serviceType);
}
This interface is consumed by the MVC framework itself. If you want to register a dependency injection container (or a service locator, for that matter), you need to provide an implementation of this interface. You can typically register an instance of the resolver inside your Global.asax file, with code much like this:
DependencyResolver.Current = new MyDependencyResolver();
Read now
Unlock full access