示例#1
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
                {
                    System.Diagnostics.Debug.WriteLine("Program Started");
                    var context     = services.GetRequiredService <SeniorLibraryContext>();
                    var userManager = services.GetRequiredService <UserManager <ApplicationUser> >();
                    var roleManager = services.GetRequiredService <RoleManager <IdentityRole> >();
                    await ContextSeed.SeedRolesAsync(userManager, roleManager);

                    await ContextSeed.SeedSuperAdminAsync(userManager, roleManager);

                    //Must have users.json in project folder!
                    await ContextSeed.AddUserAsync(userManager, roleManager);

                    await ContextSeed.AddBookAsync(context);
                }
                catch (Exception ex)
                {
                    var logger = loggerFactory.CreateLogger <Program>();
                    logger.LogError(ex, "An error occurred seeding the DB.");
                }
            }
            host.Run();
        }