public static void ServicesCollection(this IServiceCollection services) { services.AddTransient <ISyroeshkaRu, SyroeshkaRuService>(); services.AddTransient <IAdmin, AdminService>(); services.AddDbContext <ModelContext>(); services.AddTransient <UserManager <Users> >(); services.AddTransient <FormHiddenTagHelpers>(); services.AddSingleton <IHttpContextAccessor, HttpContextAccessor>(); services.AddTransient <IEdit, EditService>(); services.AddAntiforgery(t => t.HeaderName = "X-XSRF-TOKEN"); services.AddIdentity <Users, Roles>(option => { option.Password.RequiredLength = 5; option.Password.RequireNonAlphanumeric = false; option.Password.RequireLowercase = false; option.Password.RequireDigit = false; option.User.AllowedUserNameCharacters = ""; }) .AddEntityFrameworkStores <ModelContext>(); using (var serviceScope = services.BuildServiceProvider().GetRequiredService <IServiceScopeFactory>() .CreateScope()) { DbInitialize.InitRoot(serviceScope.ServiceProvider.GetRequiredService <UserManager <Users> >(), serviceScope.ServiceProvider.GetRequiredService <RoleManager <Roles> >()).Wait(); } }