Пример #1
0
        public static ServiceConfig GetServiceConfig(this IConfiguration configuration)
        {
            if (configuration == null)
            {
                throw new ArgumentNullException(nameof(configuration));
            }

            var serviceConfig = new ServiceConfig
            {
                ServiceDiscoveryAddress = configuration.GetValue <Uri>("ServiceConfig:serviceDiscoveryAddress"),
                ServiceAddress          = configuration.GetValue <Uri>("ServiceConfig:serviceAddress"),
                ServiceName             = configuration.GetValue <string>("ServiceConfig:serviceName"),
                ServiceId = configuration.GetValue <string>("ServiceConfig:serviceId"),
            };

            return(serviceConfig);
        }
 public ServiceDiscoveryHostedService(IConsulClient consulClient, ServiceConfig serviceConfig)
 {
     this._consulClient  = consulClient;
     this._serviceConfig = serviceConfig;
 }
Пример #3
0
 public ServiceDiscoveryHostedService(IConsulClient client, ServiceConfig config)
 {
     _client = client;
     _config = config;
 }
Пример #4
0
        public static IServiceCollection RegisterConsulServices(this IServiceCollection services, ServiceConfig serviceConfig)
        {
            if (serviceConfig == null)
            {
                throw new ArgumentNullException(nameof(serviceConfig));
            }

            var consulClient = CreateConsulClient(serviceConfig);

            services.AddSingleton(serviceConfig);
            services.AddSingleton <IHostedService, ServiceDiscoveryHostedService>();
            services.AddSingleton <IConsulClient, ConsulClient>(p => consulClient);
            return(services);
        }