Exemplo n.º 1
0
        public static void AddLog(this ILoggerFactory loggerFactory)
        {
            LogOption logOption = ConfigureProvider.BuildModel <LogOption>("LogOption");

            if (!logOption.EnableLog)
            {
                return;
            }
            loggerFactory.AddNLog();
            LogUtils.EnableNlog = Convert.ToBoolean(logOption.EnableLog);
            loggerFactory.ConfigureNLog(logOption.ConfigPath);
        }
Exemplo n.º 2
0
        public static IServiceCollection AddEventBus(this IServiceCollection serviceDescriptors)
        {
            eventBusOption = ConfigureProvider.BuildModel <EventBusOption>("EventBusOption");
            switch (eventBusOption.MQProvider)
            {
            case MQProvider.RabbitMQ:
                serviceDescriptors.AddSingleton <IEventBus, EventBusRabbitMQ>();
                serviceDescriptors.AddSingleton(typeof(IFactoryRabbitMQ), factiory => {
                    return(new FactoryRabbitMQ(eventBusOption));
                });
                break;
            }
            EventBusManager eventBusManager = new EventBusManager(serviceDescriptors, s => s.BuildServiceProvider());

            serviceDescriptors.AddSingleton <IEventBusManager>(eventBusManager);
            return(serviceDescriptors);
        }
Exemplo n.º 3
0
        private static ConnectionMultiplexer GetConnection()
        {
            RedisModel model   = ConfigureProvider.BuildModel <RedisModel>("Redis");
            string     connStr = string.Format("{0}:{1}", model.Host, model.Port);

            _defaultDB = model.DefaultDB;
            ConfigurationOptions options = new ConfigurationOptions()
            {
                EndPoints       = { { connStr } },
                DefaultDatabase = _defaultDB,
                //ServiceName = connStr,
                Password             = model.Password,
                ReconnectRetryPolicy = new ExponentialRetry(5000),
            };

            options.ClientName = model.InstanceName;
            return(connectionDic.GetOrAdd(connStr, s => ConnectionMultiplexer.Connect(options)));
        }
Exemplo n.º 4
0
        public static IApplicationBuilder UseConsul(this IApplicationBuilder builder)
        {
            ConsulOption model = ConfigureProvider.BuildModel <ConsulOption>("Consul");

            if (!model.Enable)
            {
                return(builder);
            }
            IConsulClient client = builder.ApplicationServices.GetRequiredService <IConsulClient>();
            string        http   = string.Format("{0}://{1}:{2}/api/health", model.Schem, model.Host, model.Port);

            AgentServiceCheck httpCheck = new AgentServiceCheck();

            httpCheck.HTTP     = http;
            httpCheck.Interval = TimeSpan.FromSeconds(model.Interval);
            httpCheck.DeregisterCriticalServiceAfter = TimeSpan.FromSeconds(model.RemoveAfterError);
            AgentServiceRegistration registration = new AgentServiceRegistration();

            registration.Address = model.Host;
            registration.Port    = Convert.ToInt32(model.Port);
            registration.ID      = string.Format("{0}.{1}", model.Host, model.Port);
            registration.Name    = model.Name;
            registration.Check   = httpCheck;
            try
            {
                client.Agent.ServiceRegister(registration).Wait();
                var lifeTime = builder.ApplicationServices.GetRequiredService <IApplicationLifetime>();
                lifeTime.ApplicationStopping.Register(() => {
                    client.Agent.ServiceDeregister(registration.ID).Wait();
                });
            }
            catch (Exception ex)
            {
                LogUtils.LogError(ex, "Core.Consul", ex.Message);
            }

            return(builder);
        }
Exemplo n.º 5
0
        /// <summary>
        /// 返回jwt模型
        /// </summary>
        /// <returns></returns>
        public static JwtOption GetOption()
        {
            JwtOption option = ConfigureProvider.BuildModel <JwtOption>("jwtOption");

            return(option);
        }