title: Error with Autofac integration with Web Api
body: <p>We have an application divided in five projects which are the following:</p>
  
  <ul>
  <li>A project with only Html pages</li>
  <li>Web Api project which functions as the service layer which only contains ApiController classes</li>
  <li>A Business layer class library</li>
  <li>A Business layer contracts class library which only contains interfaces</li>
  <li>A Data layer class library</li>
  <li>A Data layer contracts class library which also only contains interfaces</li>
  </ul>
  
  <p>The Web Api services contains references to all the class libraries as well as the Autofac and AutofacWebApiDependencyResolver.</p>
  
  <p>I have already added the necessary code to register the container and resolver as it is explained in the Autofac documentation:</p>
  
  <pre><code>    var builder = new ContainerBuilder();
      builder.RegisterApiControllers(Assembly.GetExecutingAssembly());
  
      var container = builder.Build();
      var resolver = new AutofacWebApiDependencyResolver(container);
      GlobalConfiguration.Configuration.DependencyResolver = resolver;
  </code></pre>
  
  <p>Currently I have a very basic dependency hierarchy to test this which is as follows:</p>
  
  <pre><code>//On the data contracts
  public interface IData
  {
     void SomeDataMethod();
  }
  
  //On the data layer
  public class Data : IData
  {
     public void SomeDataMethod(){}
  }
  
  //On the business contracts
  public interface IBusiness
  {
     void SomeBusinessMethod();
  }
  
  //On the business layer
  public class Business : IBusiness
  {
     private readonly IData _data;
  
     public Business(IData data)
     {
        _data = data;
     }
  }
  
  //On the Web Api project
  [EnableCors("*", "*", "*")]
  public class MyController : ApiController
  {
     private IBusiness _business;
  
     public MyController(IBusiness business)
     {
        _business = business;
     }
  }
  </code></pre>
  
  <p>So there's not rocket science at all here but when I run the project I get the following error:</p>
  
  <pre><code> XMLHttpRequest cannot load http://localhost:61101/api/MyController. No
   'Access-Control-Allow-Origin' header is present on the requested
   resource. Origin 'http://localhost:56722' is therefore not allowed
   access.
  </code></pre>
  
  <p>If I remove the constructor from the controller the application works perfectly, the controller gets instantiated and its get method gets called.</p>
  
  <p>What could I be doing wrong?</p>