Search code examples
asp.net-mvc-4dependency-injectionasp.net-web-apicontroller-factory

Possible to implement ControllerFactory and IHttpControllerActivator in MVC4 for dependency injection?


I've implemented both the ControllerFactory for Mvc Controllers and IHttpControllerActivator for WebApi Controllers like so:

ControllerBuilder.Current.SetControllerFactory(
                new MvcCompositionRoot());

GlobalConfiguration.Configuration.Services.Replace(
                    typeof(IHttpControllerActivator),
                    new WebApiCompositionRoot());

but when I send a request for the WebApi it throws an exception as the ControllerFactory is trying to resolve it. The exception is: "The controller for path '/SiteName/Account' was not found or does not implement IController."

I've tried it as a "Get" with (query string) parameters and without, but the result is the same.

Is it possible to implement both in the same project?


Solution

  • Sorry, me just being an idiot and missing "Api" from '/SiteName/Api/Account'