I am trying to customize the structure of map ver 3.0.5.0 using Web API 2.
I implemented this implementation: Configuring dependency injection using ASP.NET Web API 2.1
However, I get this error when I try to access my ComplexesController:
An error occurred while trying to create a controller of type "ComplexesController". Make sure that the controller does not have a constructor without parameters.
Can anyone see what is wrong with my mapmap configuration? The Create method is never called.
This is my implementation:
public class StructureMapControllerActivator : IHttpControllerActivator { private readonly IContainer _container; public StructureMapControllerActivator(IContainer container) { if (container == null) throw new ArgumentNullException("container"); _container = container; } public IHttpController Create(HttpRequestMessage request, HttpControllerDescriptor controllerDescriptor, Type controllerType) { try { var scopedContainer = _container.GetNestedContainer(); scopedContainer.Inject(typeof(HttpRequestMessage), request); request.RegisterForDispose(scopedContainer); return (IHttpController)scopedContainer.GetInstance(controllerType); } catch (Exception e) {
This method is in my startup ...
public void InitializeContainer() {
.. and this is the controller:
public class ComplexesController : ApiController { private IComplexRepository _repo; public ComplexesController(IComplexRepository repo) { _repo = repo; }
My full launch class
[assembly: OwinStartup(typeof(AngularJSAuthentication.API.Startup))] namespace AngularJSAuthentication.API { public class Startup { public void Configuration(IAppBuilder app) { HttpConfiguration config = new HttpConfiguration(); WebApiConfig.Register(config); app.UseWebApi(config); } } }
source share