title: Autofac - dependency injection for MVC controller and Web Api controller
body: <p>I have MVC controllers (in Controllers folder) and Web Api controllers (in Api folder) in the same project: Here is the folder structure:</p>
  
  <ul>
  <li>Controllers
  
  <ul>
  <li>ProductController</li>
  </ul></li>
  <li>Api
  
  <ul>
  <li>ProductController</li>
  </ul></li>
  </ul>
  
  <p>Here is my bootstrapper method:</p>
  
  <pre><code>        private static void SetAutofacContainer()
          {
              var builder = new ContainerBuilder();
              builder.RegisterApiControllers(Assembly.GetExecutingAssembly());
              builder.RegisterControllers(Assembly.GetExecutingAssembly());
              //builder.RegisterType&lt;UnitOfWork&gt;().As&lt;IUnitOfWork&gt;().InstancePerRequest();
              builder.RegisterType&lt;DbFactory&gt;().As&lt;IDbFactory&gt;().InstancePerRequest();
  
              // Repositories
              builder.RegisterAssemblyTypes(typeof(ProductRepository).Assembly)
                  .Where(t =&gt; t.Name.EndsWith("Repository"))
                  .AsImplementedInterfaces().InstancePerRequest();
  
              IContainer container = builder.Build();
              DependencyResolver.SetResolver(new AutofacDependencyResolver(container));
          }
  </code></pre>
  
  <p>I can not inject repositories to my Web Api controllers. Here is the exception I get:</p>
  
  <blockquote>
    <p>An error occurred when trying to create a controller of type
    'ProductController'. Make sure that the controller has a parameterless
    public constructor.</p>
  </blockquote>
  
  <p>What am I doing wrong?</p>