title: Parameterless constructor error with autofac in web api 2
body: <p>I am using Autofac as IOC and here is my structure:</p>
  <pre><code>using System;
  using System.Collections.Generic;
  using System.Linq;
  using System.Text;
  using System.Threading.Tasks;
  
  namespace AdTudent.Repo
  {
      public interface IRepository
      {
          IAdvertisementRepository Advertisements { get; set; }
          IProfileRepository Profiles { get; set; }
      }
  }
  </code></pre>
  <p>My repositories class is:</p>
  <pre><code>using System;
  using System.Collections.Generic;
  using System.Linq;
  using System.Text;
  using System.Threading.Tasks;
  
  namespace AdTudent.Repo
  {
      public class Repositories : IRepository
      {
          public Repositories(IAdvertisementRepository advertisementRepository,
                              IProfileRepository profileRepository)
          {
              Advertisements = advertisementRepository;
              Profiles = profileRepository;
          }
          public IAdvertisementRepository Advertisements { get; set; }
          public IProfileRepository Profiles { get; set; }
      }
  }
  </code></pre>
  <p>And my startup class is:</p>
  <pre><code>public partial class Startup
  {
      public void Configuration(IAppBuilder app)
      {
           var builder = new ContainerBuilder();
  
          builder.RegisterType&lt;Repositories&gt;().As&lt;IRepository&gt;();
          builder.Register&lt;IGraphClient&gt;(context =&gt;
          {
              var graphClient = new GraphClient(new Uri(&quot;http://localhost:7474/db/data&quot;));
              graphClient.Connect();
              return graphClient;
          }).SingleInstance();
          // STANDARD WEB API SETUP:
  
          // Get your HttpConfiguration. In OWIN, you'll create one
          // rather than using GlobalConfiguration.
          var config = new HttpConfiguration();
  
          // Register your Web API controllers.
          //builder.RegisterApiControllers(Assembly.GetExecutingAssembly());
  
          // Run other optional steps, like registering filters,
          // per-controller-type services, etc., then set the dependency resolver
          // to be Autofac.
         
          var container = builder.Build();
          config.DependencyResolver = new AutofacWebApiDependencyResolver(container);
  
          app.UseCors(Microsoft.Owin.Cors.CorsOptions.AllowAll);
  
          // OWIN WEB API SETUP:
  
          // Register the Autofac middleware FIRST, then the Autofac Web API middleware,
          // and finally the standard Web API middleware.
          app.UseAutofacMiddleware(container);
          app.UseAutofacWebApi(config);
          app.UseWebApi(config);
  
          ConfigureAuth(app);
      }
  }
      
  </code></pre>
  <p>and here is my account controller:</p>
  <pre><code>public class AccountController : ApiController
  {
      private  IRepository _repository;
      private const string LocalLoginProvider = &quot;Local&quot;;
      private ApplicationUserManager _userManager;
      private IGraphClient _graphClient;
     
  
      public ISecureDataFormat&lt;AuthenticationTicket&gt; AccessTokenFormat { get; private set; }       
  
      public AccountController(IRepository repository, IGraphClient graphClient,
           ISecureDataFormat&lt;AuthenticationTicket&gt; accessTokenFormat)
      {
          
          AccessTokenFormat = accessTokenFormat;
          _repository = repository;
          _graphClient = graphClient;
  
      }
  }
  </code></pre>
  <p>but I always this problem</p>
  <pre><code>&quot;Message&quot;: &quot;An error has occurred.&quot;,
  &quot;ExceptionMessage&quot;: &quot;An error occurred when trying to create a controller of type 'AccountController'. Make sure that the controller has a parameterless public constructor.&quot;,
  &quot;ExceptionType&quot;: &quot;System.InvalidOperationException&quot;,
  &quot;StackTrace&quot;: &quot;   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.&lt;SendAsync&gt;d__1.MoveNext()
  </code></pre>
  <p>I searched on the internet but I couldn't find anything that can help can anyone guide me?</p>