title: Simple Injector unable to inject dependencies in Web API controllers
body: <p>I am attempting to do some basic constructor DI with Simple Injector, and it seems that it is unable to resolve the dependencies for Web API controllers.</p>
  
  <ul>
  <li>I have an API controller in an "API" folder, that is outside the "Controllers" folder. </li>
  <li>I have also tried placing it within the "Controllers" folder, but
  that did not seem to make much of a difference. The stack trace that
  I receive is similar to the one presented in <a href="https://stackoverflow.com/questions/11347152/simpleinjector-injection-does-not-work-with-mvc-4-asp-net-web-api">this question</a>. </li>
  <li>I am using a fresh install of the "Simple Injector MVC Integration Quick Start" NuGet Package (v. 2.1.0).</li>
  <li>I have the base <code>SimpleInjectorWebApiDependencyResolver</code> from the documentation, which is also the same as found <a href="https://stackoverflow.com/questions/11254292/does-simple-injector-supports-mvc-4-asp-net-web-api">here</a>.</li>
  <li>I am using Entity Framework, and have looked at the <a href="http://simpleinjector.codeplex.com/discussions/363935" rel="noreferrer">discussion
  thread</a> about changes to correctly load the context.</li>
  </ul>
  
  <p>This does not
     seem to be a problem, but I still receive the following error:</p>
  
  <blockquote>
    <p>Type 'MyProject.API.ArticleController' does not have a default
    constructor</p>
    
    <p>System.ArgumentException at</p>
    
    <p>System.Linq.Expressions.Expression.New(Type type) at
    System.Web.Http.Internal.TypeActivator.Create[TBase](Type
    instanceType) at
    System.Web.Http.Dispatcher.DefaultHttpControllerActivator.GetInstanceOrActivator(HttpRequestMessage
    request, Type controllerType, Func`1&amp; activator) at
    System.Web.Http.Dispatcher.DefaultHttpControllerActivator.Create(HttpRequestMessage
    request, HttpControllerDescriptor controllerDescriptor, Type
    controllerType)</p>
  </blockquote>
  
  <p>It would be appreciated if someone could offer me some suggestions, on whether anything should be modified from its current state/call order.</p>
  
  <p>ArticleController (basic structure):</p>
  
  <pre><code>public class ArticleController : ApiController
  {
      private readonly IArticleRepository articleRepository;
      private readonly IUserRepository userRepository;
      private readonly IReleaseRepository releaseRepository;
  
      public ArticleController(IArticleRepository articleRepository, IUserRepository userRepository, IReleaseRepository releaseRepository)
      {
          this.articleRepository = articleRepository;
          this.userRepository = userRepository;
          this.releaseRepository = releaseRepository;
      }
  
      // GET api/Article
      public IEnumerable&lt;Article&gt; GetArticles(){ // code }
  
      // GET api/Article/5
      public Article GetArticle(int id){ // code }
  
      // PUT api/Article/5
      public HttpResponseMessage PutArticle(int id, Article article){ // code }
  
      // POST api/Article
      public HttpResponseMessage PostArticle(ArticleModel article){ // code }
  
      // DELETE api/Article/5
      public HttpResponseMessage DeleteArticle(int id){ // code }
  }
  </code></pre>
  
  <p>SimpleInjectorInitializer:</p>
  
  <pre><code>public static class SimpleInjectorInitializer
  {
      public static void Initialize()
      {
          var container = new Container();
          InitializeContainer(container);
          container.RegisterMvcControllers(Assembly.GetExecutingAssembly());
          container.RegisterMvcAttributeFilterProvider();
          container.Verify();
  
          DependencyResolver.SetResolver(new SimpleInjectorDependencyResolver(container));
      }
  
      private static void InitializeContainer(Container container)
      {
          container.Register&lt;IArticleRepository, ArticleRepository&gt;();
          container.Register&lt;IUserRepository, UserRepository&gt;();
          container.Register&lt;IReleaseRepository, ReleaseRepository&gt;();
      }
  }
  </code></pre>
  
  <p>Global.asax.cs:</p>
  
  <pre><code>public class WebApiApplication : System.Web.HttpApplication
  {
      private void ConfigureApi()
      {
          // Create the container as usual.
          var container = new Container();
  
          // Verify the container configuration
          // container.Verify();
  
          // Register the dependency resolver.
          GlobalConfiguration.Configuration.DependencyResolver =
                  new SimpleInjectorWebApiDependencyResolver(container);
      }
  
      protected void Application_Start()
      {
          AreaRegistration.RegisterAllAreas();
          ConfigureApi();
  
          WebApiConfig.Register(GlobalConfiguration.Configuration);
          FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters);
          RouteConfig.RegisterRoutes(RouteTable.Routes);
          BundleConfig.RegisterBundles(BundleTable.Bundles);
      }
  }
  </code></pre>