public GivenARedisConfig()
        {
            this.ServerAddressSettings = new RedisAddressSetting()
            {
                ServerIP = "10.220.75.22:6380",
                DbId     = 11
            };

            this.ConnectionSettings = new RedisConnectionSetting()
            {
                KeepAlive             = 5,
                SyncTimeout           = SyncTimeout,
                AbortOnConnectionFail = false,
                AllowAdmin            = true,
                ConnectionTimeout     = IoTimeOut,
                ConnectRetry          = 5
            };

            this.RedisCacheSetting = new RedisCacheSetting()
            {
                ConnectionSettings = this.ConnectionSettings,
                RedisMaster        = this.ServerAddressSettings,
                RedisSlave         = this.ServerAddressSettings
            };
        }
Example #2
0
        /// <summary>
        /// 创建链接池管理对象
        /// </summary>
        private static void CreateManager()
        {
            var settings = RedisCacheSection.GetRedisCacheSettings();

            if (settings == null || !settings.Any())
            {
                return;
            }
            RedisCacheSetting redisCacheSetting = settings.FirstOrDefault((RedisCacheSetting c) => c.Key == "BTPCache");

            if (redisCacheSetting == null)
            {
                return;
            }
            string[] writeList = new[] { redisCacheSetting.Host };
            string[] readList  = new[] { redisCacheSetting.Host };
            int      num       = string.IsNullOrEmpty(ConfigurationManager.AppSettings["RedisPoolSize"]) ? 60 : System.Convert.ToInt32(ConfigurationManager.AppSettings["RedisPoolSize"]);
            int      value     = string.IsNullOrEmpty(ConfigurationManager.AppSettings["PoolTimeOutSecond"]) ? 20 : System.Convert.ToInt32(ConfigurationManager.AppSettings["PoolTimeOutSecond"]);

            RedisClientManagerConfig redisClientManagerConfig = new RedisClientManagerConfig();

            redisClientManagerConfig.MaxWritePoolSize = num;
            redisClientManagerConfig.MaxReadPoolSize  = num;
            redisClientManagerConfig.AutoStart        = true;
            //redis = new BasicRedisClientManager(readList, writeList);
            redis = new PooledRedisClientManager(readList, writeList, redisClientManagerConfig)
            {
                PoolTimeout    = 2000,
                ConnectTimeout = 500
            };
        }
Example #3
0
        public static void RegisterComponents(UnityContainer container)
        {
            #region Infrastructures

            string serviceBusSetting = AppDomain.CurrentDomain.BaseDirectory + "InfrastructureSetting.xml";

            MobileOAuthSettings infrastructureSetting = InfrastructureSettings.Read <MobileOAuthSettings>(serviceBusSetting);
            ServiceBusConfig    serviceBusConfig      = new ServiceBusConfig(infrastructureSetting.ServiceBus);
            RedisCacheSetting   redisCacheConfig      = infrastructureSetting.RedisCache;
            serviceBusConfig.Initialize();

            container.RegisterInstance <ITextSerializer>(new JsonTextSerializer());
            container.RegisterInstance <IMetadataProvider>(new StandardMetadataProvider());
            #endregion

            #region Command Bus
            container.RegisterInstance <IMessageSender>(Topics.Commands.Path, new TopicSender(infrastructureSetting.ServiceBus, Topics.Commands.Path));

            container.RegisterInstance <ICommandBus>(
                new CommandBus(
                    container.Resolve <IMessageSender>(Topics.Commands.Path),
                    container.Resolve <IMetadataProvider>(),
                    container.Resolve <ITextSerializer>()
                    ));
            #endregion

            #region Context
            container.RegisterType <OAuthDbContext>(
                new InjectionConstructor("MobileOAuth"));
            #endregion

            #region Cache Context
            container.RegisterType <RedisReadClient>(new ContainerControlledLifetimeManager(), new InjectionConstructor(redisCacheConfig));
            container.RegisterType <RedisWriteClient>(new ContainerControlledLifetimeManager(), new InjectionConstructor(redisCacheConfig));
            #endregion

            container.RegisterInstance <IUserClient>(new UserClient());

            container.RegisterType <IApplicationRepository, ApplicationRepository>();
            container.RegisterType <IAdminUserRepository, AdminUserRepository>();

            container.RegisterType <IAppService, ApplicationService>();
            container.RegisterType <IAdminUserService, AdminUserService>();
            container.RegisterType <IDeviceService, RedisDeviceService>();
            container.RegisterType <IRefreshTokenService, RedisRefreshTokenService>();
            container.RegisterType <IUserService, UserService>();

            GlobalConfiguration.Configuration.DependencyResolver = new UnityDependencyResolver(container);
        }
        public void InstallService(IServiceCollection service, IConfiguration configuration)
        {
            RedisCacheSetting redisCacheSetting = new RedisCacheSetting();

            configuration.GetSection(nameof(RedisCacheSetting)).Bind(redisCacheSetting);

            service.AddSingleton(redisCacheSetting);

            if (redisCacheSetting.Enable)
            {
                return;
            }

            service.AddStackExchangeRedisCache(opt => opt.Configuration = redisCacheSetting.ConnectionString);
            service.AddSingleton <IResponseCacheService, ResponseCacheService>();
        }
Example #5
0
        public static void AddRedisCacheConfig(this IServiceCollection services, IConfiguration configuration)
        {
            var redisCacheOptions = new RedisCacheSetting();

            configuration.GetSection("RedisCacheSetting").Bind(redisCacheOptions);
            if (redisCacheOptions == null)
            {
                throw new Exception("Could not found redis cache settings");
            }

            services.AddDistributedRedisCache(option =>
            {
                option.Configuration = redisCacheOptions.Configuration;
                option.InstanceName  = redisCacheOptions.InstanceName;
            });
        }
Example #6
0
        // This method gets called by the runtime. Use this method to add services to the container.
        public void ConfigureServices(IServiceCollection services)
        {
            services.AddControllersWithViews()
            .AddJsonOptions(jsonOptions =>
            {
                jsonOptions.JsonSerializerOptions.PropertyNamingPolicy = null;
            });

            services.AddSwaggerGen(c =>
            {
                c.SwaggerDoc("v1", new OpenApiInfo {
                    Title = "NetCoreExample.API", Version = "v1"
                });
            });

            // Bind Configuration
            services.Configure <AppSetting>(Configuration);
            services.AddSingleton(resolver => resolver.GetRequiredService <IOptions <AppSetting> >().Value);

            // TODO: SQL Connection
            // connectionstring
            services.AddSingleton <IDbContext>(new DbContext(@"Server=192.168.0.10\SQLEXPRESS,1433;Database=TestAlex;Integrated Security=False;User Id=sa;Password=testlocal;MultipleActiveResultSets=True"));

            services.AddSingleton <IMenuRepository, MenuRepository>();
            services.AddSingleton <IMenuService, MenuService>();

            // Redis Cached
            var redisServer     = Configuration["RedisServer"];
            var redisInstance   = Configuration["RedisInstanceName"];
            var redisPassword   = Configuration["RedisPassword"];
            var redisConnString = string.Format("{0}:6379,password={1}", redisServer, redisPassword);

            var redisCacheSetting = new RedisCacheSetting();

            Configuration.GetSection(nameof(RedisCacheSetting)).Bind(redisCacheSetting);
            if (redisCacheSetting.Enabled)
            {
                services.AddStackExchangeRedisCache((options) =>
                {
                    options.Configuration = redisConnString;
                    options.InstanceName  = redisInstance;
                });
                services.AddSingleton <IResponseCacheService, ResponseCacheService>();
            }
        }
Example #7
0
        public void InstallServices(IServiceCollection services, IConfiguration configuration)
        {
            var redisCacheSetting = new RedisCacheSetting();

            configuration.GetSection(nameof(RedisCacheSetting)).Bind(redisCacheSetting);
            services.AddSingleton(redisCacheSetting);

            if (!redisCacheSetting.Enabled)
            {
                return;
            }

            services.AddDistributedSqlServerCache(option => {
                option.ConnectionString = configuration.GetConnectionString("DefaultConnection");
                option.SchemaName       = "dbo";
                option.TableName        = "Cache";
            });
            services.AddSingleton <IResponseCacheService, ResponseCacheService>();
        }
Example #8
0
        public static IUnityContainer CreateContainer()
        {
            UnityContainer container = new UnityContainer();

            #region Infrastructure

            string serviceBusSetting = AppDomain.CurrentDomain.BaseDirectory + "InfrastructureSetting.xml";
            MobileOAuthSettings infrastructureSetting = InfrastructureSettings.Read <MobileOAuthSettings>(serviceBusSetting);
            ServiceBusConfig    serviceBusConfig      = new ServiceBusConfig(infrastructureSetting.ServiceBus);
            RedisCacheSetting   redisCacheConfig      = infrastructureSetting.RedisCache;
            serviceBusConfig.Initialize();

            container.RegisterInstance <ITextSerializer>(new JsonTextSerializer());
            container.RegisterInstance <IMetadataProvider>(new StandardMetadataProvider());
            #endregion

            #region Command Bus
            // event bus
            container.RegisterInstance <IMessageSender>(Topics.Commands.Path, new TopicSender(infrastructureSetting.ServiceBus, Topics.Commands.Path));
            container.RegisterInstance <ICommandBus>(
                new CommandBus(
                    container.Resolve <IMessageSender>(Topics.Commands.Path),
                    container.Resolve <IMetadataProvider>(),
                    container.Resolve <ITextSerializer>()
                    ));
            #endregion

            #region Event Bus
            container.RegisterInstance <IMessageSender>(Topics.Events.Path, new TopicSender(infrastructureSetting.ServiceBus, Topics.Events.Path));
            container.RegisterInstance <IEventBus>(
                new EventBus(
                    container.Resolve <IMessageSender>(Topics.Events.Path),
                    container.Resolve <IMetadataProvider>(),
                    container.Resolve <ITextSerializer>()));
            #endregion

            #region Cache Context
            container.RegisterType <RedisReadClient>(new ContainerControlledLifetimeManager(), new InjectionConstructor(redisCacheConfig));
            container.RegisterType <RedisWriteClient>(new ContainerControlledLifetimeManager(), new InjectionConstructor(redisCacheConfig));
            #endregion

            #region Context
            container.RegisterType <OAuthDbContext>(
                new InjectionConstructor("MobileOAuth"));
            #endregion

            #region Repository
            container.RegisterType <IUserDeviceRepository, UserDeviceRepository>();
            #endregion

            #region CommandHandler
            container.RegisterType <ICommandHandler, OAuthViewGenerator>("OAuthViewGenerator");

            var oAuthViewGenerator =
                new CommandProcessor(new SessionSubscriptionReceiver(infrastructureSetting.ServiceBus, Topics.Commands.Path, Topics.Commands.Subscriptions.OAuthViewGenerator, false, new SessionSubscriptionReceiverInstrumentation(Topics.Commands.Subscriptions.OAuthViewGenerator, false)), container.Resolve <ITextSerializer>());

            oAuthViewGenerator.Register(container.Resolve <ICommandHandler>("OAuthViewGenerator"));

            container.RegisterInstance <IProcessor>("OAuthViewGeneratorProcessor", oAuthViewGenerator);
            #endregion

            container.RegisterEventProcessor <AuthenInfoGenerator>(serviceBusConfig, Topics.Events.Subscriptions.AuthenInfoSync, false);

            return(container);
        }