public static IKledexAppBuilder EnsureDomainDbCreated(this IKledexAppBuilder builder) { using (var serviceScope = builder.App.ApplicationServices.CreateScope()) { var dbContext = serviceScope.ServiceProvider.GetService <DomainDbContext>(); dbContext.Database.Migrate(); } return(builder); }
public static IKledexAppBuilder EnsureCosmosDbSqlDbCreated(this IKledexAppBuilder builder, IOptions <DomainDbConfiguration> settings) { var documentClient = builder.App.ApplicationServices.GetService <IDocumentClient>(); CreateDatabaseIfNotExistsAsync(documentClient, settings.Value.DatabaseId).Wait(); CreateCollectionIfNotExistsAsync(documentClient, settings.Value.DatabaseId, settings.Value.AggregateCollectionId).Wait(); CreateCollectionIfNotExistsAsync(documentClient, settings.Value.DatabaseId, settings.Value.CommandCollectionId).Wait(); CreateCollectionIfNotExistsAsync(documentClient, settings.Value.DatabaseId, settings.Value.EventCollectionId).Wait(); return(builder); }
public static IKledexAppBuilder EnsureCosmosDbCreated(this IKledexAppBuilder builder) { var dbContextFactory = builder.App.ApplicationServices.GetService <IDomainDbContextFactory>(); using (var dbContext = dbContextFactory.CreateDbContext()) { dbContext.Database.EnsureCreated(); } return(builder); }