/// <summary> 添加Nacos核心 </summary>
        /// <param name="services"></param>
        /// <param name="configAction"></param>
        /// <returns></returns>
        public static IServiceCollection AddNacosCore(this IServiceCollection services, Action <NacosConfig> configAction = null)
        {
            var config = NacosConfig.Config();

            configAction?.Invoke(config);
            services.AddSingleton(config);
            services.TryAddSingleton(provider =>
            {
                return(HttpApi.Register <INacosClient>().ConfigureHttpApiConfig(c =>
                {
                    c.HttpHost = new Uri(config.Host);
                    c.ServiceProvider = provider;
                }));
            });

            services.AddTransient(provider =>
            {
                var factory = provider.GetService <HttpApiFactory <INacosClient> >();
                return(factory.CreateHttpApi());
            });
            services.AddSingleton(provider =>
            {
                var client        = provider.GetService <INacosClient>();
                var loggerFactory = provider.GetService <ILoggerFactory>();
                return(new NacosListenerHelper(client, loggerFactory));
            });
            return(services);
        }
Exemplo n.º 2
0
 public NacosServiceFinder(NacosConfig config, INacosClient client, ILogger <NacosServiceFinder> logger, IMemoryCache cache)
     : base(cache, logger)
 {
     _config = config;
     _client = client;
     _logger = logger;
 }
Exemplo n.º 3
0
 public NacosServiceFinder(NacosConfig config, INacosClient client, ILoggerFactory loggerFactory, IMemoryCache cache)
     : base(cache)
 {
     _config = config;
     _client = client;
     loggerFactory.CreateLogger <NacosServiceFinder>();
 }
Exemplo n.º 4
0
 public NacosServiceRegister(NacosConfig config, INacosClient client, NacosListenerHelper listenerHelper, ILoggerFactory loggerFactory)
 {
     _config         = config;
     _client         = client;
     _listenerHelper = listenerHelper;
     _logger         = loggerFactory.CreateLogger <NacosServiceRegister>();
     _services       = new List <RemoveInstanceRequest>();
 }
Exemplo n.º 5
0
 public NacosConfigProvider(NacosConfig config, INacosClient client, NacosListenerHelper listenerHelper, ILoggerFactory loggerFactory,
                            string application)
 {
     _config         = config;
     _client         = client;
     _application    = application;
     _listenerHelper = listenerHelper;
     _logger         = loggerFactory.CreateLogger <NacosConfigProvider>();
 }