title: Value from generic class to generic base class
body: <p>In WebApi Core, I pass the context to a service collections via AddDataAccess. I really don't understand why the context is null at this line :</p>
  
  <pre><code>var res = this.Context.Set&lt;TEntity&gt;().AsEnumerable();
  </code></pre>
  
  <p>Some people will say because there is null in in the parameter in the constructor but to my it's correct. Should be something else.</p>
  
  <p>//In the Stratup.cs</p>
  
  <pre><code>public void ConfigureServices(IServiceCollection services)
  {
      services.AddDbContext&lt;myConnectionStringContext&gt;
          (options =&gt; options.UseSqlServer(_config["ConnectionStrings:myConnectionString"]));
      services.AddDataAccess&lt;myConnectionStringContext&gt;();
  
      // Add framework services.
      services.AddMvc();
  }
  </code></pre>
  
  <p>//In my personnal package</p>
  
  <pre><code>    public static class ServiceCollectionExtentions
      {
          public static IServiceCollection AddDataAccess&lt;TEntityContext&gt;(this IServiceCollection services) 
              where TEntityContext : DbContext
          {
              RegisterDataAccess&lt;TEntityContext&gt;(services);
              return services;
          }
  
          private static void RegisterDataAccess&lt;TEntityContext&gt;(IServiceCollection services) 
              where TEntityContext : DbContext
          {
              services.AddTransient(typeof(TEntityContext));
              services.AddTransient(typeof(IRepository&lt;&gt;), typeof(GenericEntityRepository&lt;&gt;));
          }
      }
  
  public class EntityBase
  {
      [Key]
      public int Id { get; set; }
  }
  
  public interface IRepository&lt;TEntity&gt;
  {
      IEnumerable&lt;TEntity&gt; GetAll();
  }
  
  public class GenericEntityRepository&lt;TEntity&gt; : EntityRepositoryBase&lt;DbContext, TEntity&gt; 
      where TEntity : EntityBase, new()
  {
      public GenericEntityRepository() : base(null)
      { }
  }
  
  public abstract class EntityRepositoryBase&lt;TContext, TEntity&gt; : RepositoryBase&lt;TContext&gt;, IRepository&lt;TEntity&gt; 
      where TContext : DbContext where TEntity : EntityBase, new()
  {
      protected EntityRepositoryBase(TContext context) : base(context)
      { }
  
      public virtual IEnumerable&lt;TEntity&gt; GetAll()
      {
          return this.Context.Set&lt;TEntity&gt;().AsEnumerable();
      }
  }
  
  public abstract class RepositoryBase&lt;TContext&gt; where TContext : DbContext
  {
      protected TContext Context { get; private set; }
  
      protected RepositoryBase( TContext context)
      {
         this.Context = context;
      }
  }
  </code></pre>