Created
March 4, 2020 11:51
-
-
Save GeradeDev/4456dc81f5d772803847949a0ebbb0ff to your computer and use it in GitHub Desktop.
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