public void ConfigureServices(IServiceCollection services) { var redisEndpointUrl = (Environment.GetEnvironmentVariable("REDIS_ENDPOINT_URL") ?? "127.0.0.1:6379").Split(':'); var redisHost = redisEndpointUrl[0]; var redisPort = redisEndpointUrl[1]; string redisConnectionUrl = string.Empty; var redisPassword = Environment.GetEnvironmentVariable("REDIS_PASSWORD"); if (redisPassword != null) { redisConnectionUrl = $"{redisPassword}@{redisHost}:{redisPort}"; } else { redisConnectionUrl = $"{redisHost}:{redisPort}"; } var redisManager = new RedisManagerPool(redisConnectionUrl); var redis = redisManager.GetClient(); services.AddSingleton(redis); Assembly.Load("BasicRedisLeaderboardDemoDotNetCore.BLL"); ServiceAutoConfig.Configure(services); services.AddControllers(); services.AddSpaStaticFiles(configuration => { configuration.RootPath = "ClientApp/dist"; }); }
public void ConfigureServices(IServiceCollection services) { services.AddControllers(); services.AddSwaggerGen(c => { c.SwaggerDoc("v1", new OpenApiInfo { Title = "BasicRedisChat", Version = "v1" }); var xmlFile = $"{Assembly.GetExecutingAssembly().GetName().Name}.xml"; var xmlPath = Path.Combine(AppContext.BaseDirectory, xmlFile); c.IncludeXmlComments(xmlPath); }); ConnectionMultiplexer redis = null; string redisConnectionUrl = null; { var redisSettings = new RedisSettings(); ConfigurationBinder.Bind(Configuration.GetSection("RedisSettings"), redisSettings); if (redisSettings != null) { redisConnectionUrl = $"{redisSettings.Url}:{redisSettings.Port},password={redisSettings.Password}"; } else { var redisEndpointUrl = (Environment.GetEnvironmentVariable("REDIS_ENDPOINT_URL") ?? "127.0.0.1:6379").Split(':'); var redisHost = redisEndpointUrl[0]; var redisPort = redisEndpointUrl[1]; var redisPassword = Environment.GetEnvironmentVariable("REDIS_PASSWORD"); if (redisPassword != null) { redisConnectionUrl = $"{redisHost},password={redisPassword}"; } else { redisConnectionUrl = $"{redisHost}:{redisPort}"; } } redis = ConnectionMultiplexer.Connect(redisConnectionUrl); services.AddSingleton <IConnectionMultiplexer>(redis); } services .AddDataProtection() .PersistKeysToStackExchangeRedis(redis, "DataProtectionKeys"); services.AddStackExchangeRedisCache(option => { option.Configuration = redisConnectionUrl; option.InstanceName = "RedisInstance"; }); services.AddSession(options => { options.IdleTimeout = TimeSpan.FromMinutes(30); options.Cookie.Name = "AppTest"; }); Assembly.Load("BasicRedisChat.BLL"); ServiceAutoConfig.Configure(services); services.AddAutoMapper(typeof(Startup)); services.AddHttpContextAccessor(); services.AddSingleton <IFileProvider>(new PhysicalFileProvider(Directory.GetCurrentDirectory())); services.AddSignalR(); }