// This method gets called by the runtime. Use this method to add services to the container. public void ConfigureServices(IServiceCollection services) { var connectionString = Configuration.GetConnectionString("DigitalStoreDb"); ShopManagementBoostrapper.Configur(services, connectionString); DiscountManagementBootstrapper.Configure(services, connectionString); InventoryManagementBootstrapper.Configure(services, connectionString); BlogManagementBootstrapper.Configure(services, connectionString); services.AddTransient <IFileUploader, FileUploader>(); services.AddTransient <IProductQuery, ProductQuery>(); services.AddRazorPages(); }
// This method gets called by the runtime. Use this method to add services to the container. public void ConfigureServices(IServiceCollection services) { services.AddHttpContextAccessor(); var connectionString = Configuration.GetConnectionString("LampShadeDb"); ShopManagementBoostrapper.Configure(services, connectionString); DiscountManagementBootstrapper.Configure(services, connectionString); InventoryManagementBootstrapper.Configure(services, connectionString); BlogManagementBootstrapper.Configure(services, connectionString); CommentManagementBootstrapper.Configure(services, connectionString); AccountManagementBootstrapper.Configure(services, connectionString); services.AddSingleton(HtmlEncoder.Create(UnicodeRanges.BasicLatin, UnicodeRanges.Arabic)); services.AddSingleton <IPasswordHasher, PasswordHasher>(); services.AddTransient <IFileUploader, FileUploader>(); services.AddTransient <IAuthHelper, AuthHelper>(); services.AddRazorPages(); services.Configure <CookiePolicyOptions>(options => { options.CheckConsentNeeded = context => true; options.MinimumSameSitePolicy = SameSiteMode.Lax; }); services.AddAuthentication(CookieAuthenticationDefaults.AuthenticationScheme) .AddCookie(CookieAuthenticationDefaults.AuthenticationScheme, o => { o.LoginPath = new PathString("/Account"); o.LogoutPath = new PathString("/Account"); o.AccessDeniedPath = new PathString("/AccessDenied"); }); services.AddAuthorization(options => { options.AddPolicy("AdminArea", builder => builder.RequireRole(new List <string> { Roles.Administrator, Roles.ContentUploader })); options.AddPolicy("Shop", builder => builder.RequireRole(new List <string> { Roles.Administrator })); options.AddPolicy("Discount", builder => builder.RequireRole(new List <string> { Roles.Administrator })); options.AddPolicy("Account", builder => builder.RequireRole(new List <string> { Roles.Administrator })); options.AddPolicy("Inventory", builder => builder.RequireRole(new List <string> { Roles.Administrator })); }); services.AddRazorPages() .AddMvcOptions(option => option.Filters.Add <SecurityPageFilter>()) .AddRazorPagesOptions(option => { option.Conventions.AuthorizeAreaFolder("Administration", "/", "AdminArea"); option.Conventions.AuthorizeAreaFolder("Administration", "/Shop", "Shop"); option.Conventions.AuthorizeAreaFolder("Administration", "/Discounts", "Discount"); option.Conventions.AuthorizeAreaFolder("Administration", "/Accounts", "Account"); option.Conventions.AuthorizeAreaFolder("Administration", "/Inventory", "Inventory"); }); }