//配置服务端
        public static IApplicationBuilder AddDiscoverService(this IApplicationBuilder app, string ip, string port)
        {
            ServiceConfig sc = new ServiceConfig(ip, port);

            _serviceDiscover = app.ApplicationServices.GetService <IServiceDiscover>();
            _serviceDiscover.ServiceConfig = sc;
            return(app);
        }
        //配置服务端
        public static IApplicationBuilder AddDiscoverService(this IApplicationBuilder app, Action <ServiceConfig> discoverServiceConfigOptions)
        {
            var sc = new ServiceConfig();

            discoverServiceConfigOptions(sc);
            _serviceDiscover = app.ApplicationServices.GetService <IServiceDiscover>();
            _serviceDiscover.ServiceConfig = sc;
            return(app);
        }
        //配置服务发现客户端
        public static IApplicationBuilder AddDiscoverClient(this IApplicationBuilder app, Action <ClientConfig> clientConfigOptions)
        {
            ClientConfig cc = new ClientConfig();

            clientConfigOptions(cc);
            _serviceDiscover = app.ApplicationServices.GetService <IServiceDiscover>();
            _serviceDiscover.ClientConfig = cc;
            return(app);
        }
        /// <summary>
        /// 配置服务发现客户端地址和名称
        /// </summary>
        /// <param name="app"></param>
        /// <param name="clientAddress">服务发现客户端地址</param>
        /// <param name="clientDatacenter">服务发现客户端名称</param>
        public static IApplicationBuilder AddDiscoverClient(this IApplicationBuilder app, string clientAddress, string clientDatacenter)
        {
            ClientConfig cc = new ClientConfig()
            {
                ClientAddress    = clientAddress,//
                ClientDatacenter = clientDatacenter
            };

            _serviceDiscover = app.ApplicationServices.GetService <IServiceDiscover>();
            _serviceDiscover.ClientConfig = cc;
            return(app);
        }
Ejemplo n.º 5
0
 public UserInfoController(IServiceDiscover serviceDiscover)
 {
     _serviceDiscover = serviceDiscover;
 }
Ejemplo n.º 6
0
 /// <summary>
 /// 构造函数,可以的通过di把实例化后的IServiceDiscover传给私有变量_serviceDiscover,这里我们不必关心它是consul还是别的服务发现
 /// </summary>
 /// <param name="serviceDiscover">IServiceDiscover类型的实例</param>
 public BatRequest(IServiceDiscover serviceDiscover)
 {
     _httpClient      = new HttpClient();
     _serviceDiscover = serviceDiscover;
 }