Example #1
0
        public static IServiceCollection ConfigureRedisCache(this IServiceCollection services, Action <RedisCacheSettings> redisCacheSettingspAction)
        {
            var redisCacheSettings = new RedisCacheSettings();

            redisCacheSettingspAction.Invoke(redisCacheSettings);

            services.AddSingleton(factory => redisCacheSettings);
            services.AddSingleton <IConnectionMultiplexer>(_ => ConnectionMultiplexer.Connect(redisCacheSettings.ConnectionString));
            services.AddStackExchangeRedisCache(options => options.Configuration = redisCacheSettings.ConnectionString);

            services.AddSingleton <IRedisCacheService, RedisCacheService>();

            return(services);
        }
Example #2
0
 public RedisCacheService(IDistributedCache distributedCache, RedisCacheSettings redisCacheSettings)
 {
     _distributedCache   = distributedCache;
     _redisCacheSettings = redisCacheSettings;
 }