I have a blazor server application that needs to indirectly connect to a EF core DB context.
None of the blazor components will directly inject an instance of the dbcontext. I am using mediator which will handle all business operations.
The documentation that I have seen so far recommends using IDbContextFactory. I gave it a try but I am not seeing the DbContext created by the factory being disposed. The services that inject IDbContext are not disposed on page changes nor at any other time.
public class QueryHandler : IQueryHandler<Query, Entity>, IDisposable
{
    private readonly DbContext dbContext;
    public QueryHandler(IDbContextFactory factory)
    {
        dbContext = factory.CreateDbContext();
    }
    public Task Handle(Query query)
    {
       /// do whatever needs to be done.
    }
  
    public void Dispose()
    {
        dbContext.Dispose(); // <-- Dispose never gets called.
    }
}
Am I missing something?
 
     
    