Пример #1
0
        public static IWebHost SeedSystemIdentity(this IWebHost host)
        {
            using (IServiceScope scope = host.Services.CreateScope())
            {
                IServiceProvider      services             = scope.ServiceProvider;
                UserManager <User>    userManager          = services.GetRequiredService <UserManager <User> >();
                RoleManager <Role>    roleManager          = services.GetRequiredService <RoleManager <Role> >();
                IPermissionRepository permissionRepository = services.GetRequiredService <IPermissionRepository>();
                IUserRepository       userRepository       = services.GetRequiredService <IUserRepository>();

                // TODO: обязательно в таком порядке
                IdentitySeeder identitySeeder = new IdentitySeeder(userManager, roleManager, userRepository);
                identitySeeder.SeedSystemRolesAsync().Wait();
                identitySeeder.SeedSystemUsersAsync().Wait();
                identitySeeder.SeedUserWorkgroupRoles().Wait();
                PermissionSeeder permissionSeeder = new PermissionSeeder(permissionRepository);
                permissionSeeder.SeedSystemPermissionsAsync().Wait();
            }

            return(host);
        }