dotnet / dotnet/aspnetcore

[RedisCache] Add a IServiceProvider parameter in AddStackExchangeRedisOutputCache()

Open
#57,059 1 comment 4 reactions 0 assignees View on GitHub
api-suggestion area-networking feature-caching
Dominant language
C#
Stars
38.4k
Forks
10.9k
Avg merge
2d 6h
Merged PRs (30d)
290

Description

## Background and Motivation

Since we can [use a factory to instantiate the ConnexionMultiplexer](https://github.com/dotnet/aspnetcore/issues/28379), an additional feature would be to add a IServiceProvider in parameter of `AddStackExchangeRedisOutputCache()`

I know it can be not so obvious because of the method `.Configure()` that doesn't take itself a parameter for the IServiceProvider.
I hope that this will not be an obstacle to the realization of this request.

## Proposed API

```diff
namespace Microsoft.Extensions.DependencyInjection;

public static class StackExchangeRedisOutputCacheServiceCollectionExtensions
{
public static IServiceCollection AddStackExchangeRedisOutputCache(this IServiceCollection services, Action setupAction)
{
ArgumentNullThrowHelper.ThrowIfNull(services);
ArgumentNullThrowHelper.ThrowIfNull(setupAction);

services.AddOptions();

services.Configure(setupAction);
services.AddSingleton();

return services;
}

+ public static IServiceCollection AddStackExchangeRedisOutputCache(this IServiceCollection services, Action setupAction)
+ {
+ ...
+ }
}
```

## Usage Examples

```csharp
services.AddStackExchangeRedisOutputCache(
(sp, options) =>
{
options.ConnectionMultiplexerFactory = () => Task.FromResult(sp.GetRequiredService());
}
```

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.