Beispiel #1
0
        public async static Task Main(string[] args)
        {
            var host = CreateHostBuilder(args).Build();

            using (var scope = host.Services.CreateScope())
            {
                var services      = scope.ServiceProvider;
                var loggerFactory = services.GetRequiredService <ILoggerFactory>();
                try
                {
                    var dbContextFactory = new DesignTimeStorageDbContextFactory();
                    using var storageContext = dbContextFactory.CreateDbContext(null);
                    await storageContext.Database.MigrateAsync();

                    await StorageContextSeed.SeedAsync(storageContext, loggerFactory);
                }
                catch (Exception ex)
                {
                    var logger = loggerFactory.CreateLogger <Program>();
                    logger.LogError(ex, "An error occured during migration");
                }
            }

            host.Run();
        }
Beispiel #2
0
        public static void Main(string[] args)
        {
            CreateHostBuilder(args)

            .Build()
            .MigrateDatabase <StorageContext>((context, services) =>
            {
                var logger = services.GetService <ILogger <StorageContextSeed> >();
                StorageContextSeed
                .SeedAsync(context, logger)
                .Wait();
            })
            .Run();
        }