Skip to content

Instantly share code, notes, and snippets.

@GeradeDev
Created March 4, 2020 11:51
Embed
What would you like to do?
public static IServiceCollection AddRedis(this IServiceCollection services, IConfiguration configuration)
{
var redisCacheSettings = new RedisOptions();
configuration.GetSection(SectionName).Bind(redisCacheSettings);
services.AddSingleton(redisCacheSettings);
if (!redisCacheSettings.Enabled)
{
return services;
}
services.AddSingleton<IConnectionMultiplexer>(_ => ConnectionMultiplexer.Connect(redisCacheSettings.ConnectionString));
services.AddStackExchangeRedisCache(options => options.Configuration = redisCacheSettings.ConnectionString);
services.AddSingleton<IResponseCacheService, ResponseCacheService>();
return services;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment