question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Load rules/client policies from SQL server database instead of appsettings on startup

See original GitHub issue

Hello,

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:closed
  • Created 9 months ago
  • Comments:7

github_iconTop GitHub Comments

2reactions
cristipufucommented, Dec 14, 2022

You need to remove this: builder.Services.AddInMemoryRateLimiting();

1reaction
cristipufucommented, Dec 14, 2022

Yes, you need to call it yourself when the application starts

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found