Exemple #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 getdata = services.GetRequiredService<UpLadderRespository>();
                    var context     = services.GetRequiredService <DataContext>();
                    var userManager = services.GetRequiredService <UserManager <User> >();
                    var roleManager = services.GetRequiredService <RoleManager <Role> >();
                    await context.Database.MigrateAsync();

                    await DataContextSeed.SeedAsync(context, loggerFactory);

                    //await AppIdentityDbContextSeed.SeedUsersAsync(userManager);
                    await Seed.SeedUsers(userManager, roleManager);
                }
                catch (Exception ex)
                {
                    var logger = services.GetRequiredService <ILogger <Program> >();
                    logger.LogError(ex, "An error occured during migration");
                }
            }

            host.Run();
        }
Exemple #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 <DataContext>();
                    await context.Database.MigrateAsync();

                    await DataContextSeed.SeedAsync(context, loggerFactory);

                    var userManager     = services.GetRequiredService <UserManager <AppUser> >();
                    var identityContext = services.GetRequiredService <AppIdentityDbContext>();
                    await identityContext.Database.MigrateAsync();

                    await AppIdentityDbContextSeed.SeedUserAsync(userManager);
                }
                catch (Exception e)
                {
                    var logger = loggerFactory.CreateLogger <Program>();
                    logger.LogError(e, "An error occurred during migration");
                }
            }

            await host.RunAsync();
        }
        public static async Task Main(string[] args)
        {
            //CreateHostBuilder(args).Build().Run();

            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>();
                    await context.Database.MigrateAsync();

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

                    Console.WriteLine(ex);
                    throw;
                }
            }

            host.Run();
        }
Exemple #4
0
 public static void DbInitializer(IHost host)
 {
     using (var scope = host.Services.CreateScope())
     {
         var services = scope.ServiceProvider;
         try
         {
             var context = services.GetRequiredService <DataContext>();
             DataContextSeed.SeedAsync(context).GetAwaiter();
         }
         catch (Exception ex)
         {
             var logger = services.GetRequiredService <ILogger <Program> >();
             logger.LogError(ex, "An error occurred creating Db seed data");
         }
     }
 }
Exemple #5
0
        private static async void CreateAndSeedDatabase(IHost host)
        {
            using (var scope = host.Services.CreateScope())
            {
                var services      = scope.ServiceProvider;
                var loggerFactory = services.GetRequiredService <ILoggerFactory>();

                try
                {
                    var orderContext = services.GetRequiredService <DataContext>();
                    await DataContextSeed.SeedAsync(orderContext, loggerFactory);
                }
                catch (Exception exception)
                {
                    var logger = loggerFactory.CreateLogger <Program>();
                    logger.LogError(exception.Message);
                }
            }
        }
Exemple #6
0
        public async static Task Main(string[] args)
        {
            var host = CreateHostBuilder(args).Build();

            using (var scope = host.Services.CreateScope())
            {
                try
                {
                    // Seed & migrate database if needed
                    var ctx = scope.ServiceProvider.GetRequiredService <DataContext>();
                    await ctx.Database.MigrateAsync();

                    await DataContextSeed.SeedAsync(ctx);
                }
                catch (Exception ex)
                {
                    // TODO: Add better logging system
                    Debug.WriteLine(ex);
                }
            }

            await host.RunAsync();
        }
Exemple #7
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 db = services.GetRequiredService <DataContext>();
                    await db.Database.MigrateAsync();

                    await DataContextSeed.SeedAsync(db, loggerFactory);
                }
                catch (Exception ex)
                {
                    var logger = loggerFactory.CreateLogger <Program>();
                    logger.LogError(ex.Message, "An error occur during migration");
                }
            }
            host.Run();
        }