title: How to register a inherited Generic Repository in .net core
body: <p>I have a generic repository which is inherited from <code>IDapperDbContext</code>. How can I register generic repository in <code>Startup.cs</code>?</p>
  <p>This is the code:</p>
  <p>DapperDbContext:</p>
  <pre><code>public abstract class DapperDbContext : IDapperDbContext
  {
      protected readonly IDbConnection InnerConnection;
      private DatabaseSettings dbSettings;
  
      protected DapperDbContext()
      {
          var dbOptions = Options.Create(new DatabaseSettings());
          InnerConnection = new SqlConnection(dbOptions.Value.ConnectionString);
      }
  }
  </code></pre>
  <p>Generic repository interface</p>
  <pre><code>public interface IRepository&lt;T&gt;
  {
      Task&lt;int&gt; InsertAsync(T model);
  }
  </code></pre>
  <p>Generic repository implementation</p>
  <pre><code>public abstract class Repository&lt;T&gt; : DapperDbContext, IRepository&lt;T&gt;
  {
      private readonly string _tableName;
  
      public BaseRepository(string tableName) : base()
      {
          _tableName = tableName;
      }
  
      public async Task&lt;int&gt; InsertAsync(T t)
      {
          var insertQuery = GenerateInsertQuery();
  
          using (var scope = BeginTransaction())
          {
              using (Connection)
              {
                  return await Connection.ExecuteAsync(insertQuery, t);
              }
          }
      }
  }
  </code></pre>
  <p>My student repository</p>
  <pre><code>public class StudentRepository: BaseRepository&lt;Student&gt;,IStudentRepository
  {
      public StudentRepository(string tableName):base(tableName)
      {
      }
  }
  </code></pre>
  <p>How can I register these services in <code>Startup.cs</code> and inject them into my controller as follows?</p>
  <pre><code>public class StudentController : ControllerBase
  {
      private StudentRepository _studentRepository;
  
      public StudentController(StudentRepository repository)
      {
          _studentRepository = repository;
      }
  
      [HttpPost]
      public async Task&lt;IActionResult&gt; CreateStudent(Student student)
      {
          await _studentRepository.InsertAsync(student);
          return Ok();
      }
  }
  </code></pre>