title: How to properly configure the `services.AddDbContext` of `ConfigureServices` method
body: <p>I'm trying to run an .NET Core Web application with EF Core. In order to test the repository I've added an <code>MyDbContext</code> that inherits the EF <code>DbContext</code> and interface <code>IMyDbContext</code>.</p>
  
  <pre><code>public interface IMyDbContext
  {
      DbSet&lt;MyModel&gt; Models { get; set; }
  }
  
  public class MyDbContext : DbContext, IMyDbContext
  {
      public MyDbContext(DbContextOptions&lt;MyDbContext&gt; options) : base(options)
      {
      }
  
      public virtual DbSet&lt;MyModel&gt; Models { get; set; }
  }
  </code></pre>
  
  <p>The context interface is injected to my generic repository:</p>
  
  <pre><code>public class GenericRepository&lt;TEntity&gt; : IGenericRepository&lt;TEntity&gt;
  {
      private readonly IMyDbContext _context = null;
  
      public GenericRepository(IMyDbContext context)
      {
          this._context = context;
      }
  }
  </code></pre>
  
  <p>When I use this code (without the interface) on startup.cs:</p>
  
  <pre><code>services.AddDbContext&lt;MyDbContext&gt;(options =&gt;
       options.UseSqlServer(...));
  </code></pre>
  
  <p>I'm getting a run-time error of:</p>
  
  <blockquote>
    <p>InvalidOperationException: Unable to resolve service for type
    'IMyDbContext' while attempting to activate 'GenericRepository`1[MyModel]'</p>
  </blockquote>
  
  <p>And when using this line of code:</p>
  
  <pre><code>services.AddDbContext&lt;IMyDbContext&gt;(options =&gt;
       options.UseSqlServer(...));
  </code></pre>
  
  <p>I'm getting this compiled time error code of:</p>
  
  <blockquote>
    <p>Cannot convert lambda expression to type 'ServiceLifetime' because it
    is not a delegate type</p>
  </blockquote>
  
  <p><strong>My question is how to properly configure the <code>services.AddDbContext</code> of <code>ConfigureServices</code> method?</strong>
  (Is there any changes needed inside <code>Configure</code> method?)
  If needed I'm willing to modify the IMyDbContext</p>