SimpleInjectorDependencyResolver Class

Simple Injector
MVC IDependencyResolver for Simple Injector.
Inheritance Hierarchy

SystemObject
  SimpleInjector.Integration.Web.MvcSimpleInjectorDependencyResolver

Namespace:  SimpleInjector.Integration.Web.Mvc
Assembly:  SimpleInjector.Integration.Web.Mvc (in SimpleInjector.Integration.Web.Mvc.dll) Version: 4.0.0
Syntax

public class SimpleInjectorDependencyResolver : IDependencyResolver

The SimpleInjectorDependencyResolver type exposes the following members.

Constructors

  NameDescription
Public methodSimpleInjectorDependencyResolver
Initializes a new instance of the SimpleInjectorDependencyResolver class.
Top
Properties

  NameDescription
Public propertyContainer
Gets the container.
Top
Methods

  NameDescription
Public methodGetService
Resolves singly registered services that support arbitrary object creation.
Public methodGetServices
Resolves multiply registered services.
Top
Examples

The following example shows the usage of the SimpleInjectorDependencyResolver in an MVC application:
C#
public class MvcApplication : System.Web.HttpApplication
{
    protected void Application_Start()
    {
        var container = new Container();

        // Make the container registrations, example:
        // container.Register<IUserRepository, SqlUserRepository>();

        container.RegisterMvcControllers(Assembly.GetExecutingAssembly());
        container.RegisterMvcIntegratedFilterProvider();

        // Create a new SimpleInjectorDependencyResolver that wraps the,
        // container, and register that resolver in MVC.
        System.Web.Mvc.DependencyResolver.SetResolver(
            new SimpleInjectorDependencyResolver(container));

        // Normal MVC stuff here
        AreaRegistration.RegisterAllAreas();

        RegisterGlobalFilters(GlobalFilters.Filters);
        RegisterRoutes(RouteTable.Routes);
    }
}
The previous example show the use of the RegisterMvcControllers and RegisterMvcIntegratedFilterProvider extension methods and how the SimpleInjectorDependencyResolver can be used to set the created Container instance as default dependency resolver in MVC.
See Also

Reference