title: Simple Injector - Make sure that the controller has a parameterless public constructor on production
body: <p>I am stuck with a strange situation. I am following <code>Onion Architecture</code> and my architecture is something like this:</p>
  
  <pre><code>1-Core
       - Domain Classes
       - Repository Interfaces
       - Service Interfaces
  2-Infrastructure
       - Data
       - Dependency Injection // Here I am using Simple Injector as dependency injection
       - Repository Interfaces Implementation
       - Service Interfaces Implementation
  3-WebApi
       - Web Api Project
  4-WebClient
       - My AngularJs App
  5-Test
       - Test Project
  </code></pre>
  
  <p><strong>Dependency Injection:</strong></p>
  
  <pre><code>[assembly: PreApplicationStartMethod(typeof(IocConfig), "RegisterDependencies")]
  namespace Infrastructure.DependencyResolution
  {
      public class IocConfig
      {
          public static void RegisterDependencies()
          {
              var container = new Container();
  
              container.RegisterWebApiRequest&lt;IRepositoryAsync&lt;Category&gt;, Repository&lt;Category&gt;&gt;();
              container.RegisterWebApiRequest&lt;ICategoryService, CategoryService&gt;();
              container.RegisterWebApiRequest&lt;IDataContextAsync&gt;(() =&gt; new MyContext());
              container.Verify();
              GlobalConfiguration.Configuration.DependencyResolver =
              new SimpleInjectorWebApiDependencyResolver(container);
  
          }
      }
  }
  </code></pre>
  
  <p><strong>Web Api Project:</strong></p>
  
  <pre><code>public class HomeController : ApiController
  {
      private readonly ICategoryService _categoryService;
      public HomeController(ICategoryService categoryService)
      {
          _categoryService = categoryService;
      }
  }
  </code></pre>
  
  <p>Everything is working very fine on my <code>local IIS</code>. But now I have published this application to the production server and now it is giving me below error:</p>
  
  <blockquote>
    <p>{"message":"An error has occurred.","exceptionMessage":"An error
    occurred when trying to create a controller of type 'HomeController'.
    Make sure that the controller has a parameterless public
    constructor.","exceptionType":"System.InvalidOperationException","stackTrace":"
    at
    System.Web.Http.Dispatcher.DefaultHttpControllerActivator.Create(HttpRequestMessage
    request, HttpControllerDescriptor controllerDescriptor, Type
    controllerType)\r\n at
    System.Web.Http.Controllers.HttpControllerDescriptor.CreateController(HttpRequestMessage
    request)\r\n at
    System.Web.Http.Dispatcher.HttpControllerDispatcher.d__1.MoveNext()","innerException":{"message":"An
    error has occurred.","exceptionMessage":"Type
    'JetAdz.WebApi.Controllers.HomeController' does not have a default
    constructor","exceptionType":"System.ArgumentException","stackTrace":"
    at System.Linq.Expressions.Expression.New(Type type)\r\n at
    System.Web.Http.Internal.TypeActivator.Create[TBase](Type
    instanceType)\r\n at
    System.Web.Http.Dispatcher.DefaultHttpControllerActivator.GetInstanceOrActivator(HttpRequestMessage
    request, Type controllerType, Func`1&amp; activator)\r\n at
    System.Web.Http.Dispatcher.DefaultHttpControllerActivator.Create(HttpRequestMessage
    request, HttpControllerDescriptor controllerDescriptor, Type
    controllerType)"}}</p>
  </blockquote>