コード例 #1
0
        protected EurekaDiscoveryClientBase(EurekaClientOptions clientOptions, EurekaInstanceOptions instOptions, IEurekaHttpClient httpClient, IApplicationLifetime lifeCycle = null, ILoggerFactory logFactory = null)
        {
            if (clientOptions == null)
            {
                throw new ArgumentNullException(nameof(clientOptions));
            }

            ClientConfig = clientOptions;
            InstConfig   = instOptions;

            if (InstConfig == null)
            {
                DiscoveryManager.Instance.Initialize(ClientConfig, httpClient, logFactory);
            }
            else
            {
                ConfigureInstanceIfNeeded(InstConfig);
                DiscoveryManager.Instance.Initialize(ClientConfig, InstConfig, httpClient, logFactory);
            }

            if (lifeCycle != null)
            {
                lifeCycle.ApplicationStopping.Register(() => { ShutdownAsync(); });
            }

            Client = DiscoveryManager.Instance.Client;
        }
コード例 #2
0
        internal protected virtual void Configure(IConfiguration config, EurekaClientOptions clientOptions, EurekaInstanceOptions instOptions)
        {
            ConfigurationBinder.Bind(config, clientOptions);
            ConfigurationBinder.Bind(config, instOptions);

            ClientType          = DiscoveryClientType.EUREKA;
            ClientOptions       = clientOptions;
            RegistrationOptions = instOptions;
        }
コード例 #3
0
        public static IServiceCollection AddDiscoveryClient(this IServiceCollection services, DiscoveryOptions discoveryOptions, IDiscoveryLifecycle lifecycle = null)
        {
            if (services == null)
            {
                throw new ArgumentNullException(nameof(services));
            }

            if (discoveryOptions == null)
            {
                throw new ArgumentNullException(nameof(discoveryOptions));
            }

            if (discoveryOptions.ClientType == DiscoveryClientType.EUREKA)
            {
                EurekaClientOptions clientOptions = discoveryOptions.ClientOptions as EurekaClientOptions;
                if (clientOptions == null)
                {
                    throw new ArgumentException("Missing Client Options");
                }

                services.AddSingleton <IOptionsMonitor <EurekaClientOptions> >(new OptionsMonitorWrapper <EurekaClientOptions>(clientOptions));

                var regOptions = discoveryOptions.RegistrationOptions as EurekaInstanceOptions;
                if (regOptions == null)
                {
                    clientOptions.ShouldRegisterWithEureka = false;
                    regOptions = new EurekaInstanceOptions();
                }

                services.AddSingleton <IOptionsMonitor <EurekaInstanceOptions> >(new OptionsMonitorWrapper <EurekaInstanceOptions>(regOptions));

                AddEurekaServices(services, lifecycle);
            }
            else
            {
                throw new ArgumentException("Client type UNKNOWN");
            }

            services.TryAddTransient <DiscoveryHttpMessageHandler>();
            return(services);
        }
コード例 #4
0
        public static void RegisterDiscoveryClient(this ContainerBuilder container, DiscoveryOptions discoveryOptions, IDiscoveryLifecycle lifecycle = null)
        {
            if (container == null)
            {
                throw new ArgumentNullException(nameof(container));
            }

            if (discoveryOptions == null)
            {
                throw new ArgumentNullException(nameof(discoveryOptions));
            }

            if (discoveryOptions.ClientType == DiscoveryClientType.EUREKA)
            {
                EurekaClientOptions clientOptions = discoveryOptions.ClientOptions as EurekaClientOptions;
                if (clientOptions == null)
                {
                    throw new ArgumentException("Missing Client Options");
                }

                container.RegisterInstance(new OptionsMonitorWrapper <EurekaClientOptions>(clientOptions)).As <IOptionsMonitor <EurekaClientOptions> >().SingleInstance();

                var regOptions = discoveryOptions.RegistrationOptions as EurekaInstanceOptions;
                if (regOptions == null)
                {
                    clientOptions.ShouldRegisterWithEureka = false;
                    regOptions = new EurekaInstanceOptions();
                }

                container.RegisterInstance(new OptionsMonitorWrapper <EurekaInstanceOptions>(regOptions)).As <IOptionsMonitor <EurekaInstanceOptions> >().SingleInstance();

                AddEurekaServices(container, lifecycle);
            }
            else
            {
                throw new ArgumentException("Client type UNKNOWN");
            }
        }
コード例 #5
0
 internal protected EurekaDiscoveryClient(EurekaClientOptions clientOptions, EurekaInstanceOptions instOptions, IApplicationLifetime lifeCycle = null, ILoggerFactory logFactory = null)
     : base(clientOptions, instOptions, null, lifeCycle, logFactory)
 {
     _logger = logFactory?.CreateLogger <EurekaDiscoveryClient>();
 }
コード例 #6
0
 internal protected EurekaDiscoveryClient(EurekaClientOptions clientOptions, EurekaInstanceOptions instOptions, IEurekaHttpClient httpClient, IApplicationLifetime lifeCycle = null, ILoggerFactory logFactory = null)
     : base(clientOptions, instOptions, httpClient, lifeCycle, logFactory)
 {
 }