Exemplo 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 loggerFactory = services.GetRequiredService <ILoggerFactory>();
                try
                {
                    var context     = services.GetRequiredService <DataContext>();
                    var userManager = services.GetRequiredService <UserManager <AppUser> >();
                    await context.Database.MigrateAsync();

                    Seeds.SeedData(context, userManager).Wait();
                    //await DataContextSeed.SeedAsync(context, loggerFactory);
                }
                catch (Exception ex)
                {
                    var logger = loggerFactory.CreateLogger <Program>();
                    logger.LogError(ex, "An Error occured during migration");
                }
            }

            host.Run();
        }
Exemplo n.º 2
0
        public async static 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>();
                await context.Database.MigrateAsync();
                await Seeds.SeedData(context);
            }
            catch (Exception ex)
            {
                 var logger = services.GetRequiredService<ILogger<Program>>();
                 logger.LogError(ex, "An error ocurred");
            }
            await host.RunAsync();
        }
Exemplo n.º 3
0
        public static void Main(string[] args)
        {
            var host = CreateHostBuilder(args).Build();

            using (var scope = host.Services.CreateScope())
            {
                var services = scope.ServiceProvider;
                try
                {
                    var context = services.GetRequiredService <DataContext>();
                    context.Database.Migrate();
                    Seeds.SeedData(context);
                }
                catch (Exception e)
                {
                    var logger = services.GetRequiredService <ILogger <Program> >();
                    logger.LogError(e, "An Error occured during migration");
                }
            }

            host.Run();
        }