title: How to get DBContext again after the Main Thread disposes?
body: <p>Net core. I am using EF core, Unit Of Work and Repository pattern. In my code I am releasing my main thread using await Task.Delay(150); Then I am trying to get DB Context but exception says Dbcontext is disposed. So Is there any way I can get DBContext again after the main thread disposes? below few are my code snippets,</p>
  <pre><code>services.AddDbContext&lt;MyContext&gt;(options =&gt;
             options.UseSqlServer(this.Configuration[&quot;AzureSQLConnectionString&quot;]));
  services.AddScoped&lt;IUnitOfWork, UnitOfWork&gt;();
  </code></pre>
  <p>Below is my method</p>
  <pre><code>public Class MyTestBusinessLogic : IMyTestBusinessLogic 
  {
      public MyTestBusinessLogic(IUnitOfWork unitOfWork)
      {
          UnitOfWork = unitOfWork ?? throw new ArgumentNullException(nameof(unitOfWork));
          MyTestRepository= UnitOfWork.GetRepository&lt;MyTest&gt;();
      }
      private IDbRepository&lt;MyTest&gt; MyTestRepository{ get; set; }
      public async Task MyMethod()
      {
          await MyTestRepository.GetFirstOrDefaultAsync(x =&gt; x.Id == Id); // works here 
          await Task.Delay(150);
          // here after my context disposes
          await MyTestRepository.GetFirstOrDefaultAsync(x =&gt; x.Id == Id); //this wont work and It will throw error inside GetFirstOrDefaultAsync method.
      }
  }
  </code></pre>
  <p>GetFirstOrDefaultAsync method</p>
  <pre><code>public class DbRepository&lt;T&gt; : BaseRepository&lt;T&gt;, IDbRepository&lt;T&gt; where T : class
  {
      private readonly DbContext dbContext;
      private readonly DbSet&lt;T&gt; dbSet;
      public DbRepository(DbContext dbContext)
      {
          this.dbContext = dbContext;
          this.dbSet = dbContext?.Set&lt;T&gt;();
      }
  
      public async Task&lt;T&gt; GetFirstOrDefaultAsync(Expression&lt;Func&lt;T, bool&gt;&gt; filter = null, Func&lt;IQueryable&lt;T&gt;, IOrderedQueryable&lt;T&gt;&gt; orderBy = null, params Expression&lt;Func&lt;T, object&gt;&gt;[] includes)
      {
          IQueryable&lt;T&gt; query = this.dbSet; // throws exception saying cannot use disposed object
          foreach (Expression&lt;Func&lt;T, object&gt;&gt; include in includes)
          {
              query = query.Include(include);
          }
  
          if (filter != null)
          {
              query = query.Where(filter);
          }
  
          if (orderBy != null)
          {
              query = orderBy(query);
          }
  
          return await query.FirstOrDefaultAsync().ConfigureAwait(false);
      }
  }
  </code></pre>
  <p>Can someone help me to fix this? Any help would be appreciated. Thanks</p>