Load rules/client policies from SQL server database instead of appsettings on startup
See original GitHub issueHello,
I am trying to load the rules and client policies from a SQL server database at startup instead of appsettings I found the below link
https://github.com/stefanprodan/AspNetCoreRateLimit/issues/87#issuecomment-541524848
Could you provide a bit more information on how to achieve this as I have created a class that inherits from MemoryCahceClientPolicy
`public class DatabaseCacheClientPolicyStore : MemoryCacheClientPolicyStore { private readonly IRateLimitingService rateLimitingService;
public DatabaseCacheClientPolicyStore(
IMemoryCache cache,
IOptions<ClientRateLimitOptions> options,
IOptions<ClientRateLimitPolicies> policies,
IRateLimitingService rateLimitingService)
: base(cache, options, policies)
{
this.rateLimitingService = rateLimitingService;
}
public new async Task SeedAsync()
{
var policies = await rateLimitingService.GetClientPolicies();
foreach (var rule in policies)
{
await SetAsync($"{rule.ClientId}", new ClientRateLimitPolicy { ClientId = rule.ClientId, Rules = rule.Rules });
}
}
}`
I have then registered this in program.cs
builder.Services.AddSingleton<IClientPolicyStore, DatabaseCacheClientPolicyStore>();
But this SeedAsync is not being overridden
Any help is much appreciated.
Thanks Karl
Issue Analytics
- State:
- Created 9 months ago
- Comments:7
Top Results From Across the Web
Read the IpRateLimitPolicies from a SQL Database #87
Hi, Is it possible to read the IpRateLimitPolicies from a SQL Database instead of reading them from the appSettings.json file ?
Read more >Load Application-Wide Settings During Application Startup ...
I have some application-wide settings in a database table that I want to load into memory once and utilize them throughout the lifetime...
Read more >Working with SQL Server LocalDB — ASP.NET documentation
The ApplicationDbContext class handles the task of connecting to the database and mapping Movie objects to database records. The database context is registered ......
Read more >The settings from the appsettings.json file
The appsettings.json file is generally used to store the application configuration settings such as database connection strings, ...
Read more >Lesson 1: Create & Apply an off-by-default policy - SQL ...
Tutorial that teaches you to create and apply an off-by-default policy for Policy-Based Management in SQL Server.
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
You need to remove this: builder.Services.AddInMemoryRateLimiting();
Yes, you need to call it yourself when the application starts