title: dapper with autofac and repository pattern
body: <p>I am using dapper with the repository pattern in a WebApi Application and I have the following problem.
  The Repository Class is as follows</p>
  
  <pre><code>  public class Repository : DataConnection, IRepository
    {
  
      public Repository(IDbConnection connection)
          : base(connection)
      {
  
      }
  
      public T GetFirst&lt;T&gt;(object filters) where T : new()
      {
          //Creates the sql generator
          var sqlGenerator = new MicroOrm.Pocos.SqlGenerator.SqlGenerator&lt;T&gt;();
  
          //Creates the query 
          var query = sqlGenerator.GetSelect(filters);
  
          //Execute the query
          return Connection.Query&lt;T&gt;(query, filters).FirstOrDefault();
      }
  </code></pre>
  
  <p>The IRepository Interface has only one method, the GetFirst. A Controller that uses this repository is as follows</p>
  
  <pre><code>public class UsersController : ApiController
  {
      private IRepository Repository;
  
      public UsersController(IRepository repository)
      {
          Repository = repository;
      }
  
      public User Get(int id)
      {
          return Repository.GetFirst&lt;User&gt;(new { id });
      }
  }
  </code></pre>
  
  <p>I use autofac as DI and in the Application_Start method in Global.asax I use the following code</p>
  
  <pre><code>string connString =  ConfigurationManager.ConnectionStrings["DapperDemo"].ConnectionString;
          SqlConnection connnection = new SqlConnection(connString);
          var builder = new ContainerBuilder();
          builder.RegisterType&lt;Repository&gt;().As&lt;IRepository&gt;();
          builder.RegisterType&lt;UsersController&gt;().InstancePerRequest();
          var container = builder.Build();
          var resolver = new AutofacWebApiDependencyResolver(container);
          GlobalConfiguration.Configuration.DependencyResolver = resolver;
  </code></pre>
  
  <p>But it seems that I am missing something cause I get the following error: 
  An error occurred when trying to create a controller of type 'UsersController'. Make sure that the controller has a parameterless public constructor. </p>