public static IServiceCollection AddConsulDynamicRoute(this IServiceCollection services, ConsulConfig config, Action <ConsulConfigBuilder> setup = null) { ConsulConfigBuilder builder = new ConsulConfigBuilder(config); if (setup != null) { setup(builder); } config = builder.Build(); services.AddSingleton <ConsulConfig>(a => { return(config); }); services.AddSingleton <IConsulClient>(a => { var _client = new ConsulClient(delegate(ConsulClientConfiguration obj) { obj.Address = new Uri("http://" + config.SERVICE_REGISTRY_ADDRESS + ":" + config.SERVICE_REGISTRY_PORT); obj.Datacenter = config.SERVICE_REGION; obj.Token = config.SERVICE_REGISTRY_TOKEN; }); return(_client); }); services.AddSingleton <IServiceLocator>(a => { return(new ConsulServiceLocator(config.SERVICE_REGISTRY_ADDRESS, config.SERVICE_REGISTRY_PORT, config.SERVICE_REGION, config.SERVICE_REGISTRY_TOKEN)); }); services.AddSingleton <IServiceDiscoveryProvider, ConsulServiceDiscoveryProvider>(); services.AddHostedService <ConsulServiceRegisterHostedService>(); return(services); }
public static IServiceCollection AddConsulDynamicRoute(this IServiceCollection services, ConsulConfig config, Action <ConsulConfigBuilder> setup = null) { ConsulConfigBuilder builder = new ConsulConfigBuilder(config); if (setup != null) { setup(builder); } config = builder.Build(); services.AddSingleton <ConsulConfig>(a => { return(config); }); services.AddHostedService <ConsulServiceRegisterHostedService>(); services.AddSingleton <IServiceLocator>(a => { return(new ConsulServiceLocator(config.SERVICE_REGISTRY_ADDRESS, config.SERVICE_REGISTRY_PORT, config.SERVICE_REGION, config.SERVICE_REGISTRY_TOKEN)); }); return(services); }