title: dependency injection in asp.net core with generic parameters
body: <p>I am getting the following error during usage of service collection:</p>
  <blockquote>
  <p>Error while validating the service descriptor 'ServiceType:
  HappinessMeter.BL.GenericBL.IGenericBL'1[HappinessMeter.Entity.Models.MCountry]
  Lifetime: Singleton ImplementationInstance:
  HappinessMeter.BL.EFCoreCountryBL': Constant value of type
  'HappinessMeter.BL.EFCoreCountryBL' can't be converted to service type
  'HappinessMeter.BL.GenericBL.IGenericBL`1[HappinessMeter.Entity.Models.MCountry]'</p>
  </blockquote>
  <p>in <code>Startup.cs</code></p>
  <pre class="lang-cs prettyprint-override"><code>services.Add(new ServiceDescriptor(typeof(IGenericBL&lt;MCountry&gt;), 
    new EFCoreCountryBL(new EFCoreCountryRepository(context))));
  services.Add(new ServiceDescriptor(typeof(IGenericBL&lt;User&gt;),  
     new EFCoreUserBL(new EFCoreUserRepository(context))));
  </code></pre>
  <p>my code is for EFCoreRepository is :</p>
  <pre><code>public class EFCoreRepository&lt;Tentity, Tcontext&gt; : IRepository&lt;Tentity&gt; where Tentity : class where Tcontext : DbContext
      {
          public readonly Tcontext context;
          public EFCoreRepository(Tcontext _context)
          {
              context = _context;
          }
          public async Task&lt;Tentity&gt; Add(Tentity entity)
          {
              context.Set&lt;Tentity&gt;().Add(entity);
              await context.SaveChangesAsync();
              return entity;
          }
  
          public async Task&lt;Tentity&gt; Delete(long id)
          {
              var entity = await context.Set&lt;Tentity&gt;().FindAsync(id);
              if (entity == null)
              {
                  return entity;
              }
  
              context.Set&lt;Tentity&gt;().Remove(entity);
              await context.SaveChangesAsync();
  
              return entity;
          }
  
          public async Task&lt;Tentity&gt; Get(long id) =&gt; await context.Set&lt;Tentity&gt;().FindAsync(id);
  
          public async Task&lt;List&lt;Tentity&gt;&gt; GetAll() =&gt; await context.Set&lt;Tentity&gt;().ToListAsync();
  
          public async Task&lt;Tentity&gt; Update(Tentity entity)
          {
              context.Entry(entity).State = EntityState.Modified;
              await context.SaveChangesAsync();
              return entity;
          }
      }
  </code></pre>
  <p>and EFCoreCountryRepository is</p>
  <pre><code>public class EFCoreCountryRepository : EFCoreRepository&lt;MCountry, HMDEVContext&gt;
      {
          public EFCoreCountryRepository(HMDEVContext context) : base(context)
          {
  
          }
          public async Task&lt;MCountry&gt; GetByAlpha(string alpha)
          {
              return await  context.MCountry.FirstOrDefaultAsync(x =&gt; x.Alpha2Code == alpha);
          }
  
      }
  </code></pre>