ASP.NET Core 2 + Get instance of db context : <p>I am trying to get an instance of the DbContext (so I can do some additional work upon startup with it), I get the following error when trying to get an instance in the Configure method:</p>

<p>System.InvalidOperationException: 'Cannot resolve scoped service 'MyApp.Data.MyDbContext' from root provider.'</p>

<pre><code>public void ConfigureServices(IServiceCollection services)
{
 services.AddDbContext&lt;MyDbContext&gt;(
                options =&gt; options.UseSqlServer(Configuration.GetConnectionString("MyDbContext")));
}

public void Configure(IApplicationBuilder app, IHostingEnvironment env)
{

    var dbContext = app.ApplicationServices.GetService(typeof(MyDbContext)) as MyDbContext;
}
</code></pre>

<p>I can access an instance of the DbContext fine via the controller, etc</p>
