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

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

                var dbContext = services.GetRequiredService <AppDbContext>();

                if (dbContext.Database.IsSqlServer())
                {
                    dbContext.Database.Migrate();
                }
                else if (dbContext.Database.IsInMemory())
                {
                    dbContext.Database.EnsureCreated();
                }

                if (!dbContext.Users.Any())
                {
                    var userService = services.GetRequiredService <IUserService>();
                    AppUserSeed.SeedAsync(userService).Wait();
                }

                if (dbContext.Database.IsInMemory())
                {
                    AppDbContextSeed.SeedRandomDataAsync(dbContext).Wait();
                }
            }

            host.Run();
        }