I am new to Simple Injector IOC container. I will start working in a project which will require a Multi-tenant ASP.NET MVC implementation using MVC 4 ASP.NET Web API.
<
The short answer is: yes, it works. Below is the code snippet that works for my project with both Web API and MVC4 controllers (partially based on Steven's response above):
var container = new Container();
//Register you types in container here
container.RegisterMvcControllers(Assembly.GetExecutingAssembly());
container.RegisterMvcAttributeFilterProvider();
var controllerTypes =
from type in Assembly.GetExecutingAssembly().GetExportedTypes()
where typeof(ApiController).IsAssignableFrom(type)
where !type.IsAbstract
where !type.IsGenericTypeDefinition
where type.Name.EndsWith("Controller", StringComparison.Ordinal)
select type;
foreach (var controllerType in controllerTypes)
{
container.Register(controllerType);
}
container.Verify();
DependencyResolver.SetResolver(new SimpleInjectorDependencyResolver(container));
To access your types in the API controllers you could use the following code snippet:
DependencyResolver.Current.GetService()