title: register DbContext service
body: <p>I was reading a book and get confused with Repository, below is the code:</p>
  
  <pre><code>public class ApplicationDbContext : DbContext
  {
     public ApplicationDbContext(DbContextOptions&lt;ApplicationDbContext&gt; options): base(options) { }
  
     public DbSet&lt;Product&gt; Products { get; set; }
  }
  </code></pre>
  
  <pre><code>public class EFProductRepository : IProductRepository
  {
     private ApplicationDbContext context;
  
     public EFProductRepository(ApplicationDbContext ctx)
     {
        context = ctx;
     }
  
     public IQueryable&lt;Product&gt; Products =&gt; context.Products;
  }
  </code></pre>
  
  <p>and the startup.cs</p>
  
  <pre><code>public void ConfigureServices(IServiceCollection services)
  {
     services.AddDbContext&lt;ApplicationDbContext&gt;(options =&gt; options.UseSqlServer(Configuration["Data:SportStoreProducts:ConnectionString"]));
  
     services.AddTransient&lt;IProductRepository, EFProductRepository&gt;();
  }
  </code></pre>
  
  <p>so my questions are:</p>
  
  <p>Q1-I understand that <code>services.AddTransient&lt;IProductRepository, EFProductRepository&gt;();</code> repository service so when other part of application needs a <code>IProductRepository</code>, a new <code>EFProductRepository</code> object will be given. But what about the EFProductRepository's constructor which requires an<code>ApplicationDbContext</code> object ctx, don't we need to code sth the same as:</p>
  
  <pre><code>services.AddTransient&lt;ApplicationDbContext, ...&gt;();
  </code></pre>
  
  <p>or the <code>services.AddDbContext</code> has the same effect as <code>services.AddTransient&lt;ApplicationDbContext, ...&gt;();</code></p>
  
  <p>Q2-ApplicationDbContext also has a constructor that requires a <code>DbContextOptions&lt;ApplicationDbContext&gt;</code> object options, so how this one get registered?</p>