private static IServiceProvider SetProvider(bool includeRoles) { IdentityBuilder builder = new IdentityBuilder(typeof(TUser), typeof(TRole), new ServiceCollection()); builder.Services.AddSingleton <IHttpContextAccessor, HttpContextAccessor>(); // Add Identity services to the services container. void options(IdentityOptions config) { config.Lockout = new LockoutOptions() { MaxFailedAccessAttempts = 2 }; config.Password.RequireDigit = false; config.Password.RequiredLength = 3; config.Password.RequireLowercase = false; config.Password.RequireNonAlphanumeric = false; config.Password.RequireUppercase = false; } if (includeRoles) { builder.Services.AddIdentity <TUser, TRole>(options); } else { builder.Services.AddIdentityCore <TUser>(options); } builder.AddCosmosDBStores <TContext>(() => GetConfig()) .CreateCosmosDBIfNotExists <TContext>() .AddDefaultTokenProviders(); builder.Services.AddDataProtection(); builder.Services.AddLogging(); return(builder.Services.BuildServiceProvider()); }