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

            using (var scope = host.Services.CreateScope())
            {
                var services = scope.ServiceProvider;
                var logger   = services.GetRequiredService <ILogger <Program> >();
                try
                {
                    var shopContext = services.GetRequiredService <ShopContext>();
                    await ShopContextSeed.SeedAsync(shopContext);
                }
                catch (Exception ex)
                {
                    logger.LogError(ex, "An error occured seeding th database");
                }
            }
            host.Run();
        }
Ejemplo 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;
                var loggerFactory = services.GetRequiredService <ILoggerFactory>();
                try
                {
                    var context = services.GetRequiredService <ShopContext>();
                    await context.Database.MigrateAsync();

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

            host.Run();
        }