title: How do I resolve Web API controllers using Autofac in a mixed Web API and MVC application?
body: <p>Hi I have an MVC application where I have defined some dependencies to my Web API.</p>
  
  <pre><code>public class AutofacWebApiDependenceResolver : IDependencyResolver
  {
      private readonly IComponentContext container;
      public AutofacWebApiDependenceResolver(IContainer container)
      {
  
       if (container == null)
       {
           throw new ArgumentNullException("container");
       }
       this.container = container;
      }
  
      public object GetService(Type serviceType)
      {
          if (serviceType == null)
          {
              throw new ArgumentNullException("serviceType");
          }
          var ret = this.container.ResolveOptional(serviceType) ;
          return ret;
      }
      public IEnumerable&lt;object&gt; GetServices(Type serviceType)
      {            
          if (serviceType == null)
          {
              throw new ArgumentNullException("serviceType");
          }            
          Type enumerableType = typeof(IEnumerable&lt;&gt;).MakeGenericType(serviceType);
          var ret = (IEnumerable&lt;object&gt;)this.container.ResolveOptional(enumerableType);
          return ret;
      }
  }
  </code></pre>
  
  <p>Then in my bootstrapper class I am calling it in Application_Start as follows:</p>
  
  <pre><code>GlobalConfiguration.Configuration.DependencyResolver = new AutofacWebApiDependenceResolver((IContainer)container);
  </code></pre>
  
  <p>When I debug the code, I can see there are registrations of all services with my DependencyResolver, but I am still getting the following error:</p>
  
  <blockquote>
    <p>An error has occurred.Type 'WebApp.Controllers.AuthenticateController'
    does not have a default constructor</p>
  </blockquote>
  
  <p>Here is the code to my controller:</p>
  
  <pre><code>public class AuthenticateController : ApiController
  {
      private readonly IFormsAuthenticationService formsAuthenticationService;
      private readonly IMemberShipProvider memberShip;
      private readonly IDataService dataService;
  
      public AuthenticateController(
          IMemberShipProvider memberShip,
          IFormsAuthenticationService formsAuthenticationService, IDataService dataService)
      {
          this.memberShip = memberShip;
          this.formsAuthenticationService = formsAuthenticationService;
          this.dataService= dataService;
       }
  
  }
  </code></pre>
  
  <p>How can I bring parameters to the api controllers. The Simple controllers are working fine.</p>