stefanprodan / AspNetCoreRateLimit

ASP.NET Core rate limiting middleware

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Redis Rate limiting is tightly coupled with IConnectionMultiplexer

Rashik004 opened this issue · comments

The RedisProcessingStrategy.cs file is tightly couped with IConnectionMultiplexer. The constructor has a code like below:

_connectionMultiplexer = connectionMultiplexer ?? throw new ArgumentException("IConnectionMultiplexer was null. Ensure StackExchange.Redis was successfully registered");

That means for rate limiting with Redis, we need to Use the default connection multiplexer that is registered with IConnectionMultiplexer. But if the user wants to use a different connection multiplexer for rate limiting, they have no way of doing it other than implementing a new implementation of ProcessingStrategy and registering it manually.

There should an easier option to supply the connection multiplexer instance while registering the Redis Rate limit while calling the function AddRedisRateLimiting. The signature of the function can something like below:

public static IServiceCollection AddRedisRateLimiting(this IServiceCollection services, IConnectionMultiplexer connectionMultiplexer = null)

The PR #431 Resolves this issue.