-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Limit the rate of calls made to the health/ready endpoint
- add package AspNetCoreRateLimit (5.0.0) - add it as a service in Program.cs, and configure it using the RateLimit.ConfigureServices method - configure settings in appsettings.json
- Loading branch information
1 parent
6a7fc7a
commit 2ed6128
Showing
4 changed files
with
57 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
30 changes: 30 additions & 0 deletions
30
InvestmentManager/InvestmentManager/RateLimit/RateLimit.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
using AspNetCoreRateLimit; | ||
using Microsoft.AspNetCore.Http; | ||
using Microsoft.Extensions.Configuration; | ||
using Microsoft.Extensions.DependencyInjection; | ||
|
||
namespace InvestmentManager.RateLimit | ||
{ | ||
public static class RateLimit | ||
{ | ||
public static void ConfigureServices(IServiceCollection services, IConfiguration configuration) | ||
{ | ||
// needed to load configuration from appsettings.json | ||
services.AddOptions(); | ||
// needed to store rate limit counters and ip rules | ||
services.AddMemoryCache(); | ||
//load general configuration from appsettings.json | ||
services.Configure<IpRateLimitOptions>(configuration.GetSection("IpRateLimiting")); | ||
//load ip rules from appsettings.json | ||
services.Configure<IpRateLimitPolicies>(configuration.GetSection("IpRateLimitPolicies")); | ||
// inject counter and rules stores | ||
services.AddSingleton<IIpPolicyStore, MemoryCacheIpPolicyStore>(); | ||
services.AddSingleton<IRateLimitCounterStore, MemoryCacheRateLimitCounterStore>(); | ||
// Add framework services. | ||
services.AddMvc(); | ||
services.AddSingleton<IHttpContextAccessor, HttpContextAccessor>(); | ||
// configuration (resolvers, counter key builders) | ||
services.AddSingleton<IRateLimitConfiguration, RateLimitConfiguration>(); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters