示例#1
0
        public static async Task Main(string[] args)
        {
            var host = CreateHostBuilder(args).Build();

            using (var scope = host.Services.CreateScope())
            {
                var context = scope.ServiceProvider.GetRequiredService <ApplicationDbContext>();
                context.Database.Migrate();
                var roleManager = scope.ServiceProvider.GetRequiredService <RoleManager <IdentityRole> >();
                await DefaultRoles.AddDefaultRolesAsync(roleManager);

                var userManager = scope.ServiceProvider.GetRequiredService <UserManager <ApplicationUser> >();
                await DefaultUsers.AddDefaultUsers(userManager);
            }
            host.Run();
        }
示例#2
0
        public static async Task Main(string[] args)
        {
            var    host = CreateHostBuilder(args).Build();
            string connectionString;

            using (var scope = host.Services.CreateScope())
            {
                IConfiguration configuration = scope.ServiceProvider.GetRequiredService <IConfiguration>();
                connectionString = configuration.GetConnectionString("Default");
            }
            Migration.ConnectionString = connectionString;
            await Migration.MigrateAsync();

            DefaultUsers.ConnectionString = connectionString;
            await DefaultUsers.AddDefaultUsers();

            DefaultAuthors.ConnectionString = connectionString;
            await DefaultAuthors.AddDefaultAuthors();

            DefaultCategories.ConnectionString = connectionString;
            await DefaultCategories.AddDefaultCategories();

            await host.RunAsync();
        }