This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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