예제 #1
0
        /// <summary>
        /// Adds the services.
        /// </summary>
        /// <param name="services">Services.</param>
        public void AddServices(IServiceCollection services)
        {
            services.AddOptions();

            services.TryAddSingleton <IEasyCachingSerializer, DefaultBinaryFormatterSerializer>();

            services.Configure(_name, _configure);

            services.AddSingleton <EasyCachingCSRedisClient>(x =>
            {
                var optionsMon = x.GetRequiredService <IOptionsMonitor <CSRedisBusOptions> >();
                var options    = optionsMon.Get(_name);

                var conns = options.ConnectionStrings;
                var rule  = options.NodeRule;

                if (conns.Count == 1)
                {
                    var redisClient = new EasyCachingCSRedisClient(_name, conns[0]);
                    return(redisClient);
                }
                else
                {
                    var redisClient = new EasyCachingCSRedisClient(_name, rule, conns.ToArray());
                    return(redisClient);
                }
            });

            services.AddSingleton <IEasyCachingBus, DefaultCSRedisBus>();
        }
예제 #2
0
 /// <summary>
 /// Initializes a new instance of the <see cref="T:EasyCaching.Bus.CSRedis.DefaultCSRedisBus"/> class.
 /// </summary>
 /// <param name="clients">Clients.</param>
 public DefaultCSRedisBus(IEnumerable <EasyCachingCSRedisClient> clients)
 {
     this.BusName = "easycachingbus";
     this._client = clients.FirstOrDefault(x => x.Name.Equals("easycachingbus"));
 }