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 · 4 comments
Open

Use dependency injection for IConnectionMultiplexer #5

cristipufu opened this issue Nov 6, 2022 · 4 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;
        }));
}

@infofromca
Copy link

infofromca commented Oct 7, 2024

when you redesign this , please keep in mind that IConnectionMultiplexer can come from another application (system) , right now it is ok because there is a public property for IConnectionMultiplexer

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

5 participants
@infofromca @cristipufu @BenasBud @GimmeDaKitty and others