Пример #1
0
        private void ConfigureDependencies(IServiceCollection services)
        {
            //see: https://github.com/aspnet/Hosting/issues/793
            services.AddSingleton <IHttpContextAccessor, HttpContextAccessor>();

            services.AddSingleton(sp => sp.GetService <IOptions <SiteConfig> >().Value);
            services.AddTransient(sp => ElasticClientFactory.GetClient(sp));

            // Add DependencyAttribute (ScopedDependency, SingletonDependency, TransientDependency) to the class in order to be scanned
            services.ConfigureAttributedDependencies();

            {
                var options = ConfigurationOptions.Parse(Configuration["SlambyApi:Redis:Configuration"]);
                //HACK: https://github.com/dotnet/corefx/issues/8768
                //this should be removed when https://github.com/dotnet/corefx/issues/11564 is closed
                options = RedisDnsHelper.CorrectOption(options);
                if (options == null)
                {
                    Log.Logger.Error("Can't resolve the name of the Redis server!");
                    return;
                }
                services.AddSingleton(RedisDnsHelper.CorrectOption(options));
                services.AddSingleton <ConnectionMultiplexer>(sp => ConnectionMultiplexer.Connect(sp.GetService <ConfigurationOptions>()));
            }
        }
Пример #2
0
        public ThrottleService(ConnectionMultiplexer redis, SiteConfig siteConfig, ILoggerFactory loggerFactory)
        {
            if (siteConfig.Stats != null && siteConfig.Stats.Enabled)
            {
                var options = ConfigurationOptions.Parse(siteConfig.Stats.Redis.Configuration);
                options.CommandMap = CommandMap.Create(siteConfig.Stats.Redis.CommandMap);

                options = RedisDnsHelper.CorrectOption(options);
                if (options != null)
                {
                    centralRedis = ConnectionMultiplexer.Connect(options);
                }
            }
            this.redis  = redis;
            this.logger = loggerFactory.CreateLogger <ThrottleService>();
        }