Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use dependency injection for IConnectionMultiplexer #5

Open
cristipufu opened this issue Nov 6, 2022 · 3 comments
Open

Use dependency injection for IConnectionMultiplexer #5

cristipufu opened this issue Nov 6, 2022 · 3 comments
Labels
enhancement New feature or request

Comments

@cristipufu
Copy link
Owner

No description provided.

@cristipufu cristipufu added the enhancement New feature or request label Nov 6, 2022
@GimmeDaKitty
Copy link

I'm trying to figure out what needs to be done here, would it be possible to add some description?

@cristipufu
Copy link
Owner Author

I don't really like the fact that we have to send the 'ConnectionMultiplexer' as an option to the rate limiters - wanted to somehow get it behind-the-hood from the Services Container.

However, I don't think there's much we can do for now - we're limited by the way the framework's rate limiting middleware works and is configured

@BenasBud
Copy link

If wanted you can use the HTTP context RequestServices more details here, or can use IPostConfigureOptions<RateLimiterOptions>.

Maybe this example will help someone:

public static RateLimiterOptions AddRedisFixedWindowLimiter(this RateLimiterOptions options, string policyName,
    Action<RedisFixedWindowRateLimiterOptions, IServiceProvider> configure)
{
    ArgumentNullException.ThrowIfNull(configure, nameof(configure));
    
    var key = new PolicyNameKey(policyName);
    return options.AddPolicy(policyName, (context) =>
        RedisRateLimitPartition.GetFixedWindowRateLimiter(key, (_) =>
        {
            var windowsOptions = new RedisFixedWindowRateLimiterOptions();
            configure(windowsOptions, context.RequestServices);
            return windowsOptions;
        }));
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

4 participants
@cristipufu @BenasBud @GimmeDaKitty and others