title: Override Lifetime in ASP.NET Core Dependency Injection
body: <p>I've registered an Entity Framework DBContext using standard code like this:</p>
  
  <pre><code>public void ConfigureServices(IServiceCollection services)
  {
      [...]
      services.AddDbContext&lt;MyDbContextType&gt;(ServiceLifetime.Scoped);
  }
  </code></pre>
  
  <p>And this works just great for services called from controllers that require EF services.</p>
  
  <p>However I have a couple of controllers that are special. They start jobs on new threads that run past the lifetime of the web request. When these jobs use my DbContext (or use services that use my DbContext) an error is thrown because the scoped instance has already been disposed.</p>
  
  <p>Is there a way to override the service lifetime of my injected DbContext just for certain controllers? Or is there another solution you could suggest?</p>