title: Can I clone DbContext from existing one?
body: <p>I'm working on .NET Core Web API and I have one endpoint where I want to run three operations in parallel. All three of them use the same database, so I need three copies of DbContext. I created a simple Factory class, which I later inject into my "Data" class.</p>
  
  <p>Is it possible (if it's, is a good practice), to inject DbContext into my factory class (using built in .NET Core IoC) and when someone calls "CreateMyDbContext" method, just deep clone the one which was injected at the beginning?</p>
  
  <p><strong>EDIT:</strong>
  Here is the example with the DbContext Pool:</p>
  
  <pre><code>public class FooData : IFooData
  {
      private readonly Func&lt;DisposableScopedContextWrapper&gt; _func;
  
      public FooData(Func&lt;DisposableScopedContextWrapper&gt; func)
      {
          _func = func;
      }
  
      public async Task&lt;List&lt;Apple&gt;&gt; GetApples()
      {
          using (var wrapper = _func())
          {
              var apples = await wrapper.Context.Apples.FromSqlRaw("SELECT.... complicated query").ToListAsync();
              return apples;
          }
      }
  
      public async Task&lt;List&lt;Orange&gt;&gt; GetOranges()
      {
          using (var wrapper = _func())
          {
              var oranges = await wrapper.Context.Oranges.FromSqlRaw("SELECT.... complicated query").ToListAsync();
              return oranges;
          }
      }
  }
  
  
  public class FooService
  {
      private readonly IFooData _fooData;
  
      public FooData(IFooData fooData)
      {
          _fooData = fooData;
      }
  
      public async Task&lt;List&lt;Fruit&gt;&gt; GetFruits()
      {
          var appleTask = _fooData.GetApples();
          var orangeTask = _fooData.GetOranges();
  
          (var result1, var result2) = await (appleTask, orangeTask).WhenAll();
  
          // ... 
      }
  }
  </code></pre>