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

AddRedisQueryStorage Throws & Inconsistent API #3470

Closed
RehanSaeed opened this issue Apr 9, 2021 · 1 comment · Fixed by #3833
Closed

AddRedisQueryStorage Throws & Inconsistent API #3470

RehanSaeed opened this issue Apr 9, 2021 · 1 comment · Fixed by #3833
Assignees
Labels
Milestone

Comments

@RehanSaeed
Copy link
Contributor

Describe the bug

If I remove x.GetApplicationServices() below, Hot Chocolate is unable to resolve IConnectionMultiplexer and throws an exception.

services.AddSingleton<IConnectionMultiplexer>(ConnectionMultiplexer.Connect("localhost:6379"));

builder.AddRedisQueryStorage(x => x.GetApplicationServices().GetRequiredService<IConnectionMultiplexer>().GetDatabase());

Additionally, there is some inconsistency in the way that we resolve a IConnectionMultiplexer in AddRedisQueryStorage and AddRedisSubscriptions. In one call we have to get a database, while in the other we don't.

builder.AddRedisSubscriptions(x => x.GetRequiredService<IConnectionMultiplexer>());

Expected behavior

The code below should not throw and should be able to resolve IConnectionMultiplexer. Additionally, I suggest removing the additional need to call .GetDatabase() in AddRedisQueryStorage.

services.AddSingleton<IConnectionMultiplexer>(ConnectionMultiplexer.Connect("localhost:6379"));

builder.AddRedisQueryStorage(x => x.GetRequiredService<IConnectionMultiplexer>());
@michaelstaib
Copy link
Member

This one is now implemented. We now allow the following:

Variant 1:

services.AddSingleton<IConnectionMultiplexer>(ConnectionMultiplexer.Connect("localhost:6379"));

builder.AddRedisQueryStorage(x => x.GetRequiredService<IConnectionMultiplexer>().GetDatabase());

Variant 2:

services.AddSingleton<IConnectionMultiplexer>(ConnectionMultiplexer.Connect("localhost:6379"));

builder.AddRedisQueryStorage(x => x.GetRequiredService<IConnectionMultiplexer>());

Variant 3:

services.AddSingleton<IConnectionMultiplexer>(ConnectionMultiplexer.Connect("localhost:6379"));

// this will get the first registered multiplexer.
builder.AddRedisQueryStorage();

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

Successfully merging a pull request may close this issue.

2 participants