// This method gets called by the runtime. Use this method to add services to the container. public void ConfigureServices(IServiceCollection services) { services.AddOptions(); services.AddMemoryCache(); //configure ip rate limiting middle-ware services.Configure <IpRateLimitOptions>(Configuration.GetSection("IpRateLimiting")); services.Configure <IpRateLimitPolicies>(Configuration.GetSection("IpRateLimitPolicies")); services.AddSingleton <IIpPolicyStore, MemoryCacheIpPolicyStore>(); services.AddSingleton <IRateLimitCounterStore, MemoryCacheRateLimitCounterStore>(); //configure client rate limiting middleware services.Configure <ClientRateLimitOptions>(Configuration.GetSection("ClientRateLimiting")); services.Configure <ClientRateLimitPolicies>(Configuration.GetSection("ClientRateLimitPolicies")); services.AddSingleton <IClientPolicyStore, MemoryCacheClientPolicyStore>(); //services.AddSingleton<IRateLimitCounterStore, MemoryCacheRateLimitCounterStore>(); //configure client rate limiting middleware services.Configure <UserRateLimitOptions>(Configuration.GetSection("UserRateLimiting")); services.Configure <UserRateLimitPolicies>(Configuration.GetSection("UserRateLimitPolicies")); services.AddSingleton <IUserPolicyStore, MemoryCacheUserPolicyStore>(); var opt = new ClientRateLimitOptions(); ConfigurationBinder.Bind(Configuration.GetSection("ClientRateLimiting"), opt); var optUser = new UserRateLimitOptions(); ConfigurationBinder.Bind(Configuration.GetSection("UserRateLimiting"), optUser); services.AddTransient <IPeopleRepository, PeopleRepository>(); services.AddTransient <IPersonCarRepository, PersonCarRepository>(); services.AddTransient <ICarRepository, CarRepository>(); // Add DbContext var conStr = Configuration["Data:ApplicationDb:ConnectionString"]; services.AddScoped((_) => new ApplicationDbContext(conStr)); // Add framework services. //services.AddMvc(); services.AddMvc().AddJsonOptions(options => { options.SerializerSettings.ContractResolver = new CamelCasePropertyNamesContractResolver(); options.SerializerSettings.ReferenceLoopHandling = ReferenceLoopHandling.Ignore; }); services.AddSwaggerGen(); services.ConfigureSwaggerGen(options => { options.SingleApiVersion(new Info { Version = "v1", Title = "Swashbuckle Test API", Description = "A simple example ASP.NET Core Web API", TermsOfService = "None", Contact = new Contact { Name = "Darren Schwarz", Email = "*****@*****.**", Url = "http://www.darrenschwarz.com" }, License = new License { Name = "Use under LICX", Url = "http://url.com" } }); //Determine base path for the application. var basePath = PlatformServices.Default.Application.ApplicationBasePath; //Set the comments path for the swagger json and ui. options.IncludeXmlComments(basePath + "\\SwashbuckleExample.xml"); }); services.AddAuthentication(options => new IISOptions() { ForwardWindowsAuthentication = true }); services.AddAuthorization(options => { options.AddPolicy("IOAdmin", policy => policy.Requirements.Add(new RoleRequirement("IOAdmin"))); options.AddPolicy("SomeOther", policy => policy.Requirements.Add(new RoleRequirement("SomeOther"))); }); services.AddSingleton <IAuthorizationHandler, RoleHandler>(); var r = Configuration.GetSection("Role"); }
public UserRateLimitRuntimeController(IOptions <UserRateLimitOptions> optionsAccessor, IUserPolicyStore userPolicyStore) { _options = optionsAccessor.Value; _userPolicyStore = userPolicyStore; }