Class DbContextMigrationUtility
- Assembly
- Stratara.EventSourcing.EntityFrameworkCore.dll
Helper for applying pending EF Core migrations across a set of DbContext option builders — typically used by host startup to ensure the target databases exist and are up to date before workers start.
public static class DbContextMigrationUtility
- Inheritance
-
DbContextMigrationUtility
- Inherited Members
Methods
MigrateAllDatabasesAsync<TDbContext>(IServiceProvider, IEnumerable<DbContextOptionsBuilder<TDbContext>>)
For each DbContextOptionsBuilder<TContext> in optionsBuilders,
creates a context, ensures its database exists, and applies any pending migrations.
public static Task MigrateAllDatabasesAsync<TDbContext>(this IServiceProvider serviceProvider, IEnumerable<DbContextOptionsBuilder<TDbContext>> optionsBuilders) where TDbContext : DbContext
Parameters
serviceProviderIServiceProviderThe host service provider used to create a scope.
optionsBuildersIEnumerable<DbContextOptionsBuilder<TDbContext>>Pre-configured option builders, one per target database.
Returns
- Task
A task that completes when every database has been migrated.
Type Parameters
TDbContextThe DbContext type being migrated.
Exceptions
- InvalidOperationException
Thrown if
TDbContextcannot be instantiated via its DbContextOptions<TContext> constructor.