Beispiel #1
0
        public static IServiceCollection AddDistributeSession(this IServiceCollection services, Action <DistributeSessionConfig> configAction)
        {
            var config = new DistributeSessionConfig();

            configAction?.Invoke(config);
            services.AddHttpContextAccessor();
            services.AddTransient <ISession, DistributeSession>();
            services.AddSingleton(config);
            return(services);
        }
        public DistributeSession(IHttpContextAccessor httpContextAccessor, ILogger <DistributeSession> logger, DistributeSessionConfig sessionConfig)
        {
            this.logger = logger;
            this.config = sessionConfig;
            redisDB     = new CSRedisClient(sessionConfig.RedisConnectionString);
            RedisHelper.Initialization(redisDB);

            if (sessionConfig.IsApiMode)
            {
                this.Id = this.GetSessionIdByHeader(httpContextAccessor.HttpContext);
            }
            else
            {
                this.Id = this.GetSessionIdByCookies(httpContextAccessor.HttpContext);
            }
        }