This project is read-only.

Web API Support

Jun 22, 2012 at 4:58 PM

I'm having trouble using SimpleInjector with MVC4/Web API, I've installed it as per the MVC3 way and in SimpleInjectorInitializer::InitializeContainer() I register my repository, however when I execute a controller that uses this repository I get:


Type 'Core.Controllers.CountryController' does not have a default constructor

Why would this be?

Jun 22, 2012 at 5:15 PM

It seems that the problem may be down to the controller type, Controller normally implements IController etc, however under the new Web API the ApiController class is defined as:

public abstract class ApiController : IHttpController, IDisposable

Whilst in your code you explicitly check for IController compatibility so the controller is never found :/

Jun 29, 2012 at 11:05 AM

Take a look at this stackoverflow answer. It will answer your question.

Marked as answer by dot_NET_Junkie on 11/4/2013 at 1:56 AM