Esempio n. 1
0
        //private class NacosClientConfigurationContainer
        //{

        //    internal readonly bool skipClientDispose;
        //    internal readonly HttpClient HttpClient;

        //    internal readonly HttpClientHandler HttpHandler;

        //    public readonly NacosClientConfiguration Config;

        //    public NacosClientConfigurationContainer()
        //    {
        //        Config = new NacosClientConfiguration();
        //        HttpHandler = new HttpClientHandler();
        //        HttpClient = new HttpClient(HttpHandler);
        //        HttpClient.Timeout = TimeSpan.FromMinutes(15);
        //        HttpClient.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
        //        HttpClient.DefaultRequestHeaders.Add("Keep-Alive", "true");
        //    }

        //    #region Old style config handling
        //    public NacosClientConfigurationContainer(NacosClientConfiguration config, HttpClient client)
        //    {
        //        skipClientDispose = true;
        //        Config = config;
        //        HttpClient = client;
        //    }

        //    public NacosClientConfigurationContainer(NacosClientConfiguration config)
        //    {
        //        Config = config;
        //        HttpHandler = new HttpClientHandler();
        //        HttpClient = new HttpClient(HttpHandler);
        //        HttpClient.Timeout = TimeSpan.FromMinutes(15);
        //        HttpClient.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
        //        HttpClient.DefaultRequestHeaders.Add("Keep-Alive", "true");
        //    }
        //    #endregion
        //}

        //public NacosClient() : this(null)
        //{

        //}

        //public NacosClient(Action<NacosClientConfiguration> configOverride) : this(configOverride, null)
        //{

        //}

        //public NacosClient(Action<NacosClientConfiguration> configOverride, Action<HttpClient> clientOverride) : this(configOverride, clientOverride, null)
        //{

        //}

        //public NacosClient(Action<NacosClientConfiguration> configOverride, Action<HttpClient> clientOverride, Action<HttpClientHandler> handlerOverride)
        //{
        //    var ctr = new NacosClientConfigurationContainer();
        //    configOverride?.Invoke(ctr.Config);
        //    ApplyConfig(ctr.Config, ctr.HttpHandler, ctr.HttpClient);
        //    handlerOverride?.Invoke(ctr.HttpHandler);
        //    clientOverride?.Invoke(ctr.HttpClient);
        //    ConfigContainer = ctr;
        //}

        //void ApplyConfig(NacosClientConfiguration config, HttpClientHandler handler, HttpClient client)
        //{

        //}



        //public NacosNamingClient(
        //    ILoggerFactory loggerFactory
        //    , NacosDiscoveryOptions optionAccs
        //    , IHttpClientFactory clientFactory
        //    )
        //{

        //}


        public NacosNamingClient(
            ILoggerFactory loggerFactory
            , IOptionsMonitor <NacosDiscoveryOptions> optionAccs
            , IHttpClientFactory clientFactory
            )
        {
            this._logger        = loggerFactory.CreateLogger <NacosNamingClient>();
            this._options       = optionAccs.CurrentValue;
            this._clientFactory = clientFactory;

            //this.listeners = new List<Listener>();
            this._serverAddressManager = new ServerAddressManager(_options);
        }
        public ServerAddressManager(NacosDiscoveryOptions options)
        {
            var serverAddresses = options.Host;

            Init(serverAddresses);
        }