Simple Injector IDependencyResolver implementation.
Inheritance Hierarchy
SimpleInjector.Integration.WebApiSimpleInjectorWebApiDependencyResolver
Namespace: SimpleInjector.Integration.WebApi
Assembly: SimpleInjector.Integration.WebApi (in SimpleInjector.Integration.WebApi.dll) Version: 5.3.0
Syntax
public sealed class SimpleInjectorWebApiDependencyResolver : IDependencyResolver, IDependencyScope, IDisposable
The SimpleInjectorWebApiDependencyResolver type exposes the following members.
Constructors
Name | Description | |
---|---|---|
SimpleInjectorWebApiDependencyResolver(Container) |
Initializes a new instance of the SimpleInjectorWebApiDependencyResolver class with
the default scope option (i.e. to use an ambient AsyncScopedLifestyle
scope if one already exists).
| |
SimpleInjectorWebApiDependencyResolver(Container, DependencyResolverScopeOption) |
Initializes a new instance of the SimpleInjectorWebApiDependencyResolver class.
|
Methods
Name | Description | |
---|---|---|
Dispose |
Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged
resources.
|
Explicit Interface Implementations
Name | Description | |
---|---|---|
IDependencyResolver.BeginScope | Starts a resolution scope. | |
IDependencyScope.GetService | Retrieves a service from the scope. | |
IDependencyScope.GetServices | Retrieves a collection of services from the scope. |
Examples
C#
using System.Web.Http; using SimpleInjector; using SimpleInjector.Integration.WebApi; public static class WebApiConfig { public static void Register(HttpConfiguration config) { var container = new Container(); // Make the container registrations, example: // container.Register<IUserRepository, SqlUserRepository>(); container.RegisterWebApiControllers(config); container.RegisterWebApiFilterProvider(config); // Create a new SimpleInjectorDependencyResolver that wraps the, // container, and register that resolver in MVC. container.Verify(); config.DependencyResolver = new SimpleInjectorWebApiDependencyResolver(container); config.Routes.MapHttpRoute( name: "DefaultApi", routeTemplate: "api/{controller}/{id}", defaults: new { id = RouteParameter.Optional } ); } }
See Also