Description
openedon Nov 6, 2024
Not sure if Docs is the proper place to write this, but looking forward for a feedback.
So I am using .NET 8 rate limits in a production app, and I am finding myself couple of limitations and my feeling is the first iteration of the library. I will enumerate:
- A rate limit should allow having OnReject per each limit.
Expected API:
options.AddXXX("policyName", options =>
options.OnRejected = .....
Currently this functionality can be achieved by checking policy name by using if statements. However would be nice to have the reject attached to the policy as well
- An overload with options.AddRateLimit("name", PartitionedRateLimiter instance) should be added. With the current design there is a discrepancy when you create a policy using options.AddXX and the GlobalLimiter.
Expected behavior should be that everywhere should be using a PartitionedRateLimiter instance, similar with the current design of GlobalLimiter.
Also all the existing functions to add policy, should should call this new overload
For example, currently if you want to create a chained policy you use this API:
var ipRateLimit = PartitionedRateLimiter.Create<HttpContext, string>(CreateIpLimitPartition);
var concurrencyLimit = PartitionedRateLimiter.Create<HttpContext, string>(CreateConcurrencyLimitPartition);
options.GlobalLimiter = PartitionedRateLimiter.CreateChained(ipRateLimit, concurrencyLimit);
Using the same API, you should also use call options.Add("mypolicy", result_of_chained_policy)
Currently I could not find any way to achieve such a thing, even analysing the code,
I had a look to the current design and implementing this would affect several files.