title: Entity Framework Core - disposed when trying to run 2nd Query
body: <p>I have an issue with a database context being disposed. I have set up the databases like the below in the Configure services method. The code has been simplified to hopefully make it easier to read.</p>
  
  <pre><code>public void ConfigureServices(IServicesCollection services)
  {
        Services.AddDbContext&lt;ApplicationDbContext&gt;(options =&gt; options.UseSqlServer(Configuration.GetConnectionString("Database1")));
        Services.AddDbContext&lt;ApplicationDbContext&gt;(options =&gt; options.UseSqlServer(Configuration.GetConnectionString("Database2")));
        Services.AddDbContext&lt;ApplicationDbContext&gt;(options =&gt; options.UseSqlServer(Configuration.GetConnectionString("Database3")));
        Services.AddDbContext&lt;ApplicationDbContext&gt;(options =&gt; options.UseSqlServer(Configuration.GetConnectionString("Database4")));
  
        Services.AddScoped&lt;IQueryService1, ConcreteService1&gt;();
        Services.AddScoped&lt;IQueryService1, ConcreteService2&gt;();
        Services.AddScoped&lt;IQueryService1, ConcreteService3&gt;();
        Services.AddScoped&lt;IQueryService1, ConcreteService4&gt;();
  }
  </code></pre>
  
  <p>Now in one of the controllers I inject the relevant services that are required.</p>
  
  <pre><code>[Produces("application/json")]
  [Route("api/[controller]/[action]
  public class DigitalFinesController : Controller
  {
        private readonly IQueryService1 _Service1;
  
        public DigitalFinesController(IConfiguration configuration, IQueryServices1 QueryService1)
        {
           _Service1 = QueryService1;
        }
  
        [Authorize]
        [HttpPost]
        [ActionName("SubmitFine")]
        [ProducesResponseType(200)]
        [ProducesResponseType(401)]
        public async Task&lt;IActionResult&gt; SubmitFine([FromBody] Models.DigitalFine fine)
        {
           //This is a simple version of my issue
           var vehicles = _Service1.Vehicles.FirstOrDefault(p=&gt; p.vrm == "OX7 DFG");
           if(vehicle == null)
           {
              return BadRequest("Vehicle is missing");
           }
  
           var fleet = _Service1.Fleets.FirstOrDefault(p=&gt; p.Code = "MyCode");
        }
  }
  </code></pre>
  
  <p>And once I get to the second query I get the following exception</p>
  
  <blockquote>
    <p>System.ObjectDisposedException: 'Cannot access a disposed object. A common cause of this error is disposing a context that was resolved from dependency injection and then later trying to use the same context instance elsewhere in your application. This may occur if you are calling Dispose() on the context, or wrapping the context in a using statement. If you are using dependency injection, you should let the dependency injection container take care of disposing context instances.</p>
  </blockquote>
  
  <p>And I am stumped to understand why this is happening. Can anyone please give me a pointer to fix this?</p>
  
  <p>Many thanks
  Simon</p>