/// <summary>
        /// Withs the redis bus.
        /// </summary>
        /// <returns>The redis bus.</returns>
        /// <param name="options">Options.</param>
        /// <param name="configuration">Configuration.</param>
        /// <param name="sectionName">Section name.</param>
        public static EasyCachingOptions WithRedisBus(this EasyCachingOptions options, IConfiguration configuration, string sectionName = EasyCachingConstValue.RedisBusSection)
        {
            var dbConfig     = configuration.GetSection(sectionName);
            var redisOptions = new RedisBusOptions();

            dbConfig.Bind(redisOptions);

            void configure(RedisBusOptions x)
            {
                x.AbortOnConnectFail = redisOptions.AbortOnConnectFail;
                x.AllowAdmin         = redisOptions.AllowAdmin;
                x.Configuration      = redisOptions.Configuration;
                x.ConnectionTimeout  = redisOptions.ConnectionTimeout;
                x.Database           = redisOptions.Database;
                x.IsSsl    = redisOptions.IsSsl;
                x.Password = redisOptions.Password;
                x.SslHost  = redisOptions.SslHost;

                foreach (var item in redisOptions.Endpoints)
                {
                    x.Endpoints.Add(item);
                }
            }

            options.RegisterExtension(new RedisBusOptionsExtension(configure));
            return(options);
        }
 /// <summary>
 /// Initializes a new instance of the <see cref="T:EasyCaching.Bus.Redis.DefaultRedisBus"/> class.
 /// </summary>
 /// <param name="name">Unique name of the bus.</param>
 /// <param name="subscriberProviders">Subscriber provider.</param>
 /// <param name="busOptions">bus Options.</param>
 /// <param name="serializers">Serializers.</param>
 public DefaultRedisBus(
     string name
     , IEnumerable <IRedisSubscriberProvider> subscriberProviders
     , RedisBusOptions busOptions
     , IEnumerable <IEasyCachingSerializer> serializers)
 {
     this._name               = name ?? throw new ArgumentNullException(nameof(name));;
     this.BusName             = name;
     this._subscriberProvider = subscriberProviders.Single(x => x.SubscriberName.Equals(name));
     this._serializer         = !string.IsNullOrWhiteSpace(busOptions.SerializerName)
         ? serializers.Single(x => x.Name.Equals(busOptions.SerializerName))
         : serializers.Single(x => x.Name.Equals(EasyCachingConstValue.DefaultSerializerName));
     this._subscriber = _subscriberProvider.GetSubscriber();
 }
        /// <summary>
        /// Adds the default redis bus.
        /// </summary>
        /// <returns>The default redis bus.</returns>
        /// <param name="services">Services.</param>
        /// <param name="optionsAction">Options action.</param>
        public static IServiceCollection AddDefaultRedisBus(this IServiceCollection services, Action <RedisBusOptions> optionsAction)
        {
            ArgumentCheck.NotNull(services, nameof(services));
            ArgumentCheck.NotNull(optionsAction, nameof(optionsAction));

            var options = new RedisBusOptions();

            optionsAction?.Invoke(options);
            services.AddSingleton(options);

            services.TryAddSingleton <IEasyCachingSerializer, DefaultBinaryFormatterSerializer>();
            services.TryAddSingleton <IEasyCachingBus, DefaultRedisBus>();
            services.TryAddSingleton <IEasyCachingSerializer, DefaultBinaryFormatterSerializer>();
            services.TryAddSingleton <IRedisSubscriberProvider, RedisSubscriberProvider>();
            //services.TryAddSingleton<IEasyCachingProvider, DefaultRedisCachingProvider>();

            return(services);
        }
Esempio n. 4
0
 /// <summary>
 /// Initializes a new instance of the <see cref="T:EasyCaching.Bus.Redis.RedisSubscriberProvider"/> class.
 /// </summary>
 /// <param name="options">Options.</param>
 public RedisSubscriberProvider(IOptions <RedisBusOptions> options)
 {
     _options = options.Value;
     _connectionMultiplexer = new Lazy <ConnectionMultiplexer>(CreateConnectionMultiplexer);
 }
 /// <summary>
 /// Initializes a new instance of the <see cref="T:EasyCaching.Redis.RedisDatabaseProvider"/> class.
 /// </summary>
 /// <param name="options">Options.</param>
 public RedisSubscriberProvider(RedisBusOptions options)
 {
     _options = options;
     _connectionMultiplexer = new Lazy <ConnectionMultiplexer>(CreateConnectionMultiplexer);
 }
Esempio n. 6
0
 /// <summary>
 /// Initializes a new instance of the <see cref="T:EasyCaching.Bus.Redis.RedisSubscriberProvider"/> class.
 /// </summary>
 /// <param name="name">name.</param>
 /// <param name="options">Options.</param>
 public RedisSubscriberProvider(string name, RedisBusOptions options)
 {
     _name    = name;
     _options = options;
     _connectionMultiplexer = new Lazy <ConnectionMultiplexer>(CreateConnectionMultiplexer);
 }