Exemplo n.º 1
0
        public void InstallServices(IServiceCollection services, IConfiguration configuration)
        {
            var redisCachingSettings = new RedisCachingSettings();

            configuration.GetSection(nameof(RedisCachingSettings)).Bind(redisCachingSettings);
            services.AddSingleton(redisCachingSettings);

            if (!redisCachingSettings.Enabled)
            {
                return;
            }
            services.AddSingleton <IConnectionMultiplexer>(_ => ConnectionMultiplexer.Connect(redisCachingSettings.ConnectionString));
            services.AddStackExchangeRedisCache(options => options.Configuration = redisCachingSettings.ConnectionString);
            services.AddSingleton <IResponseCacheService, ResponseCacheService>();
        }
Exemplo n.º 2
0
        public static IServiceCollection AddRedisCache(this IServiceCollection services, IConfiguration configuration)
        {
            RedisCachingSettings redisCachingSettings = new RedisCachingSettings();

            configuration.GetSection("RedisCachingSettings").Bind(redisCachingSettings);
            services.AddSingleton(redisCachingSettings);

            //to validate the token which has been sent by clients


            services.AddEasyCaching(opt =>
            {
                if (redisCachingSettings.IsEnabled)
                {
                    opt.UseRedis(rd => rd.DBConfig.Endpoints.Add(new ServerEndPoint(redisCachingSettings.Host, redisCachingSettings.Port)), "Redis");
                }
            });

            return(services);
        }