private static IServiceCollection AddRestEaseClient <T>(this IServiceCollection services, string serviceName, RestEaseOptions options, Action <IServiceCollection> registerFabio) where T : class { var clientName = typeof(T).ToString(); switch (options.LoadBalancer?.ToLowerInvariant()) { case "consul": services.AddConsulHttpClient(clientName, serviceName); break; case "fabio": services.AddFabioHttpClient(clientName, serviceName); break; default: ConfigureDefaultClient(services, clientName, serviceName, options); break; } ConfigureForwarder <T>(services, clientName); registerFabio(services); return(services); }
private static void ConfigureDefaultClient(IServiceCollection services, string clientName, string serviceName, RestEaseOptions options) { services.AddHttpClient(clientName, client => { var service = options.Services.SingleOrDefault(s => s.Name.Equals(serviceName, StringComparison.InvariantCultureIgnoreCase)); if (service is null) { throw new RestEaseServiceNotFoundException($"RestEase service: '{serviceName}' was not found.", serviceName); } client.BaseAddress = new UriBuilder { Scheme = service.Scheme, Host = service.Host, Port = service.Port }.Uri; }); }
public static IServiceCollection AddRestEaseClient <T>(this IServiceCollection builder, string serviceName, RestEaseOptions options, ConsulOptions consulOptions, FabioOptions fabioOptions, HttpClientOptions httpClientOptions) where T : class => builder.AddRestEaseClient <T>(serviceName, options, b => b.AddFabio(fabioOptions, consulOptions, httpClientOptions));