public async Task <ConsulServiceResult> RegistAsync(ConsulService service)
        {
            if (_client.IsNull())
            {
                return(new ConsulServiceResult(false, "", "", ""));
            }

            await _client.Agent.ServiceRegister(
                new AgentServiceRegistration
            {
                ID      = service.Id,
                Name    = service.Name,
                Address = service.Host,
                Port    = service.Port,
                Tags    = service.Tags,
                Check   = new AgentServiceCheck {
                    HTTP     = service.HealthCheckOptoins.HealthCheckHTTP,
                    Interval = service.HealthCheckOptoins.IntervalTimeSpan,
                    DeregisterCriticalServiceAfter = service.HealthCheckOptoins.DeRegisterDelayTimeSpan
                }
            }).ConfigureAwait(false);

            return(new ConsulServiceResult(true));
        }
        public static IApplicationBuilder UseConsul(this IApplicationBuilder app, IApplicationLifetime lifetime, ConsulService service)
        {
            var serviceRegister = new ConsulServiceRegister(service.HostConfiguration);

            serviceRegister.RegistAsync(service).ConfigureAwait(false).GetAwaiter().GetResult();

            lifetime.ApplicationStopping.Register(() =>
            {
                serviceRegister.DeregisterAsync(service).ConfigureAwait(false).GetAwaiter().GetResult();
            });

            return(app);
        }
        public async Task <ConsulServiceResult> DeregisterAsync(ConsulService service)
        {
            var result = await _client.Agent.ServiceDeregister(service.Id);

            return(result.StatusCode == HttpStatusCode.OK ? null : new ConsulServiceResult(false, "", "", ""));
        }