title: How to register repository pattern under configure service on startup class
body: <p><strong>How to register  Generic Repository pattern on startup class under configure service function ?</strong></p>
  <p>I try to register repository pattern on configure service function on startup.cs as below but i get error</p>
  <blockquote>
  <p>InvalidOperationException: Unable to resolve service for type 'TabDataAccess.Repositories.RepositoryTab`1[TabDataAccess.Dto.Employee]'
  while attempting to activate
  'WebTabCore.Controllers.EmployeeController'.</p>
  </blockquote>
  <pre><code>    public void ConfigureServices(IServiceCollection services)
              {
      
      services.AddScoped(typeof(IrepositoryTab&lt;&gt;), typeof(RepositoryTab&lt;&gt;));
  services.AddDbContext&lt;TabDbContext&gt;(options =&gt;
        options.UseSqlServer(Configuration.GetConnectionString(&quot;DefaultConnection&quot;)));
              }
  </code></pre>
  <p><strong>Code details</strong></p>
  <pre><code>public class Employee   
  {   
  public int EmployeeId { get; set; }    
  public string EmployeeName { get; set; }   
  } 
  
  
   public class TabDbContext : DbContext
      {
          public TabDbContext(DbContextOptions&lt;TabDbContext&gt; options)
  : base(options)
          { }
  
          public DbSet&lt;Employee&gt; Employees { get; set; }
      }
  
  public class RepositoryTab : IrepositoryTab where T : class   
  {   
  protected TabDbContext db { get; set; }   
  private DbSet dbSet;  
  public RepositoryTab(TabDbContext Tabdb)   
  {              
  db = Tabdb;              
  dbSet = db.Set();   
  }   
  public IEnumerable GetAll()   
  {  
   return dbSet.ToList();  
  }   
  }  
  
  public interface IrepositoryTab where T : class
   {
   IEnumerable GetAll();        
  
   }  
  </code></pre>
  <p>On EmployeeController</p>
  <pre><code>public class EmployeeController : Controller
   {
      
      private readonly IrepositoryTab&lt;Employee&gt; _repository;
      public EmployeeController(RepositoryTab&lt;Employee&gt; emp)
      {
          this._repository = emp;
      }
      public IActionResult Index()
      {
          var employees = _repository.GetAll();
          return View(employees);
      }
  }
  </code></pre>