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

            using (var scope = host.Services.CreateScope()) {
                var services = scope.ServiceProvider;

                try
                {
                    var context     = services.GetRequiredService <DataContext>();
                    var userManager = services.GetRequiredService <UserManager <AppUser> >();
                    context.Database.Migrate();
                    await Seed.SeedDataAsync(context, userManager);
                }
                catch (Exception ex)
                {
                    var logger = services.GetRequiredService <ILogger <Program> >();
                    logger.LogError(ex, "An error occured during migration");
                }
            }

            host.Run();
        }
Esempio n. 2
0
        public static async Task Main(string[] args)
        {
            var host = CreateHostBuilder(args).Build();

            using var scope = host.Services.CreateScope();
            var services = scope.ServiceProvider;

            try
            {
                var context     = services.GetRequiredService <DataContext>();
                var userManager = services.GetRequiredService <UserManager <User> >();

                await context.Database.MigrateAsync();

                await Seed.SeedDataAsync(context, userManager);
            }
            catch (Exception ex)
            {
                var logger = services.GetRequiredService <ILogger <Program> >();

                logger.LogError(ex, "Ошибка, вызванная вовремя миграции");
            }
            await host.RunAsync();
        }
Esempio n. 3
0
        public static async Task Main(string[] args)
        {
            var host = CreateWebHostBuilder(args).Build();

            using (var scope = host.Services.CreateScope())
            {
                var services = scope.ServiceProvider;
                try
                {
                    var context = services.GetRequiredService <DataContext>();
                    //Assurer la migration avant l'éxecution.
                    context.Database.Migrate();

                    await Seed.SeedDataAsync(context);
                }
                catch (Exception ex)
                {
                    var logger = services.GetRequiredService <ILogger>();
                    logger.LogError(ex, "An error accured wen executing database creation.");
                }
            }

            host.Run();
        }