using FreeRedis; using Microsoft.Extensions.Caching.Distributed; using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.DependencyInjection.Extensions; using Volo.Abp.Caching; using Volo.Abp.Modularity; namespace NPin.Framework.Caching.FreeRedis; /// /// FreeRedis支持分布式缓存(IDistributedCache),与abp无缝斜街 /// [DependsOn(typeof(AbpCachingModule))] public class NPinFrameworkCachingFreeRedisModule : AbpModule { public override void ConfigureServices(ServiceConfigurationContext context) { var configuration = context.Services.GetConfiguration(); var enabled = configuration["Redis:IsEnabled"]; if (enabled.IsNullOrEmpty() || bool.Parse(enabled)) { var redisConfiguration = configuration["Redis:Configuration"]; var redisClient = new RedisClient(redisConfiguration); context.Services.AddSingleton(redisClient); context.Services.Replace(ServiceDescriptor.Singleton(new DistributedCache(redisClient))); } } }