'IDbContextFactory for Blazor: when to use CreateDbContextAsync the async version vs CreateDbContext

I started using IDbContextFactory.CreateDbContext when working on Blazor server projects. I know this interface was created for Blazor to resolve the DbContext concurrency issue in a stateful Blazor server app.

So far I've always been doing

using var context = _contextFactory.CreateDbContext();
//Then use the context...

But I just found that there is an async version of the method, IDbContextFactory.CreateDbContextAsync which the documentation simply says "Creates a new DbContext instance in an async context".

So my question is should I prefer one version over another? Is the context creation an expensive/potentially blocking operation that warrants async operation?



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source