public override void MigrateDbContext(IWebHost host) { host.MigrateDbContext <WebsocketContext>((context, services) => { }) .MigrateDbContext <EventLogContext>((context, services) => { }); }
private void RunWebHost(string[] args) { var configuration = GetConfiguration(); Serilog.Log.Logger = CreateSerilogLogger(configuration); try { Serilog.Log.Information("Configuring web host ({ApplicationContext})...", Program.AppName); webHost = BuildWebHost(configuration, args); Serilog.Log.Information("Applying migrations ({ApplicationContext})...", Program.AppName); webHost .MigrateDbContext <RepairContext>((context, services) => { InitData(context);//TODO:初始化种子数据 }).MigrateDbContext <IntegrationEventLogContext>((c, s) => { }); Serilog.Log.Information("Starting web host ({ApplicationContext})...", Program.AppName); //webHost.Run(); webHost.Start(); } catch (Exception ex) { Serilog.Log.Fatal(ex, "Program terminated unexpectedly ({ApplicationContext})!", Program.AppName); } finally { Serilog.Log.CloseAndFlush(); } }
public static IWebHost RegisterDbContext(this IWebHost webHost) { return(webHost .MigrateDbContext <ApplicationDbContext>((context, services) => { InstanceSeedData(services, context, typeof(ISeedData <>)); })); }
public static IWebHost RegisterDbContext <TDbContext>(this IWebHost webHost) where TDbContext : DbContext { return(webHost .MigrateDbContext <TDbContext>((context, services) => { InstanceSeedData(services, context, typeof(ISeedData <>)); })); }
public static IWebHost MigrationAndSeedDataDB(this IWebHost webHost) { Task.WaitAll( webHost.MigrateDbContextAsync <IDS4DbContext>(EnsureSeedIDS4DataAsync), webHost.MigrateDbContextAsync <AppIdentityDbContext>(EnsureSeedIdentityDataAsync) ); webHost.MigrateDbContext <EventStoreContext>(null); return(webHost); }
public static IWebHost BuildContext(this IWebHost builder) { builder .MigrateDbContext <AplicationDbContext>((context, services) => { var applicationDbContextSeed = services.GetService <AplicationDbContextSeed>(); applicationDbContextSeed.EnsureSeedAsync().Wait(); }); return(builder); }
public static IWebHost MigrateDb(this IWebHost host) { host.MigrateDbContext <BeersContext>((context, services) => { var logger = services.GetService <ILogger <BeersContextSeed> >(); new BeersContextSeed() .SeedAsync(context, logger) .Wait(); }); return(host); }
public static IWebHost RegisterDbContexts(this IWebHost webHost) { return(webHost .MigrateDbContext <PersistedGrantDbContext>((_, __) => { }) .MigrateDbContext <ConfigurationDbContext>((context, services) => { InstanceSeedData(services, context, typeof(IAuthConfigSeedData <>)); }) .MigrateDbContext <Data.ApplicationDbContext>((context, services) => { InstanceSeedData(services, context, typeof(ISeedData <>)); })); }
/// <summary> /// Migrate Web host extension /// </summary> /// <returns></returns> private static IWebHost Migrate() { AppState.InstallOnProgress = true; GlobalWebHost? .MigrateDbContext <EntitiesDbContext>() .MigrateDbContext <GearIdentityDbContext>() .MigrateDbContext <MenuDbContext>(); SystemEvents.Database.MigrateAll(EventArgs.Empty); return(GlobalWebHost); }
public override void MigrateDbContext(IWebHost host) { host.MigrateDbContext <PaymentWebhookContext>((context, services) => { var env = services.GetService <IWebHostEnvironment>(); var settings = services.GetService <IOptions <BaseSettings> >(); var logger = services.GetService <ILogger <PaymentWebhookContextSeed> >(); new PaymentWebhookContextSeed() .SeedAsync(context, env, settings, logger) .Wait(); }) .MigrateDbContext <EventLogContext>((context, services) => { }); }
public static int Main(string[] args) { var configuration = GetConfiguration(); Serilog.ILogger log = CreateSerilogLogger(configuration); Log.Logger = log; try { Log.Information("Configuring web host ({ApplicationContext})...", AppName); host = BuildWebHost(configuration, log, args); Log.Information("Applying migrations ({ApplicationContext})...", AppName); _ = host.MigrateDbContext <AdminDbContext>((context, services) => { var env = services.GetService <IHostingEnvironment>(); var settings = services.GetService <IOptions <ProgramSettings> >(); var logger = services.GetService <ILogger <AdminDbContextSeed> >(); new AdminDbContextSeed() .SeedAsync(context, env, settings, logger) .Wait(); }); Log.Information("Starting web host ({ApplicationContext})...", AppName); host.Run(); return(0); } catch (Exception ex) { Log.Fatal(ex, "Program terminated unexpectedly ({ApplicationContext})!", AppName); return(1); } finally { Log.CloseAndFlush(); } }
/// <summary> /// Migrate Web host extension /// </summary> /// <returns></returns> private static IWebHost Migrate() { AppState.InstallOnProgress = true; GlobalWebHost? .MigrateDbContext <EntitiesDbContext>() .MigrateDbContext <ApplicationDbContext>() .MigrateDbContext <MenuDbContext>() .MigrateDbContext <PersistedGrantDbContext>() .MigrateDbContext <ConfigurationDbContext>((context, services) => { var config = services.GetService <IConfiguration>(); var env = services.GetService <IHostingEnvironment>(); var applicationDbContext = services.GetRequiredService <ApplicationDbContext>(); var configurator = new IdentityServer4Configurator(); IdentityServerConfigDbSeeder.SeedAsync(configurator, context, applicationDbContext, config, env) .Wait(); }); SystemEvents.Database.Migrate(new DatabaseMigrateEventArgs()); return(GlobalWebHost); }
public static IWebHost DbContextRegistration(this IWebHost webHost) { return(webHost .MigrateDbContext <PersistedGrantDbContext>((_, __) => { }) .MigrateDbContext <ConfigurationDbContext>((context, services) => { var env = services.GetService <IHostingEnvironment>(); var logger = services.GetService <ILogger <ApplicationDbContextSeed> >(); var configuration = services.GetService <IConfiguration>(); new ConfigurationDbContextSeed() .SeedAsync(context, configuration) .Wait(); }) .MigrateDbContext <Data.ApplicationDbContext>((context, services) => { var env = services.GetService <IHostingEnvironment>(); var logger = services.GetService <ILogger <ApplicationDbContextSeed> >(); new ApplicationDbContextSeed() .SeedAsync(context, env, logger) .Wait(); })); }
public static int Main(string[] args) { try { IWebHost host = BuildWebHost(args); _logger = host.Services.GetService <ILogger <Program> >(); _environment = host.Services.GetService <IHostingEnvironment>(); _logger.LogInformation($"Webhost built ({_environment.ApplicationName})!"); _logger.LogInformation($"The environment is ({_environment.EnvironmentName})!"); if (_environment.IsDevelopment() || _environment.IsStaging()) { host.MigrateDbContext <SqlServerMessagingContext>((context, services) => { var logger = services.GetService <ILogger <SqlServerMessagingContextSeed> >(); // Seeding database logger.LogInformation($"Seeding database associated with context {typeof(SqlServerMessagingContext).Name}"); SqlServerMessagingContextSeed sqlServerMessagingContextSeed = new SqlServerMessagingContextSeed(context); sqlServerMessagingContextSeed.SeedAsync().Wait(); logger.LogInformation($"Seeded database associated with context {typeof(SqlServerMessagingContext).Name}"); }); } _logger.LogInformation($"Running Webhost ({_environment.ApplicationName})!"); host.Run(); return(0); } catch (Exception ex) { _logger?.LogCritical(ex, $"Program terminated unexpectedly ({_environment.ApplicationName})!"); return(1); } }
public override void MigrateDbContext(IWebHost host) { host.MigrateDbContext <ApplicationDbContext>((_, __) => {}) .MigrateDbContext <EventLogContext>((_, __) => { }); }
/// <summary> /// Migrate db context /// </summary> /// <typeparam name="TContext"></typeparam> /// <param name="webHost"></param> /// <returns></returns> public static IWebHost MigrateDbContext <TContext>(this IWebHost webHost) where TContext : DbContext { return(webHost.MigrateDbContext <TContext>((context, services) => { })); }
public override void MigrateDbContext(IWebHost host) { host.MigrateDbContext <PermissionContext>((context, services) => {}) .MigrateDbContext <EventLogContext>((context, services) => { }); }