title: Using Autofac with Web Api 2 and Owin
body: <p>Im new to DI libraries and trying to use Autofac in a WebApi 2 project with Owin. This is my Owin Startup class,</p>
  
  <pre><code>[assembly: OwinStartup(typeof(FMIS.SIGMA.WebApi.Startup))]
  namespace FMIS.SIGMA.WebApi
  {
      public class Startup
      {
          public void Configuration(IAppBuilder app)
          {
              var builder = new ContainerBuilder();
              var config = new HttpConfiguration();
              WebApiConfig.Register(config);
              builder.RegisterApiControllers(Assembly.GetExecutingAssembly());
              var container = builder.Build();
              config.DependencyResolver = new AutofacWebApiDependencyResolver(container);
              app.UseAutofacMiddleware(container);
              app.UseAutofacWebApi(config);
              app.UseWebApi(config);
  
              ConfigureOAuth(app);
          }
  
          public void ConfigureOAuth(IAppBuilder app)
          {
              OAuthAuthorizationServerOptions OAuthServerOptions = new OAuthAuthorizationServerOptions()
              {
                  AllowInsecureHttp = true,
                  TokenEndpointPath = new PathString("/token"),
                  AccessTokenExpireTimeSpan = TimeSpan.FromDays(1),
                  Provider = new SimpleAuthorizationServerProvider()
              };
  
              // Token Generation
              app.UseOAuthAuthorizationServer(OAuthServerOptions);
              app.UseOAuthBearerAuthentication(new OAuthBearerAuthenticationOptions());
  
          }
  
      }
  }
  </code></pre>
  
  <p>When I call a Api method I get this error</p>
  
  <blockquote>
    <p>An error occurred when trying to create a controller of type
    'MyController'. Make sure that the controller has a
    parameterless public constructor.</p>
  </blockquote>
  
  <p>What am I missing here?</p>
  
  <hr>
  
  <p><em>MyController</em> code is something like this</p>
  
  <pre><code>public class MyController : ApiController
      {
          ISomeCommandHandler someCommanHandler;
  
          public MyController(ISomeCommandHandler SomeCommandHandler)
          {
              this.someCommanHandler = SomeCommandHandler;
  
          }
  
          // POST: api/My
          public void Post([FromBody]string value)
          {
              someCommanHandler.Execute(new MyCommand() { 
                  Name = "some value"
              });
          }
  
          // GET: api/My
          public IEnumerable&lt;string&gt; Get()
          {
  
          }
  
          // GET: api/My/5
          public string Get(int id)
          {
  
          }
      }
  </code></pre>