public static void Register(IServiceCollection services, ApiClientsOptions options) { foreach (var desc in options.List) { var normUrl = desc.Value.Url == null || desc.Value.Url.EndsWith("/") ? desc.Value.Url : desc.Value.Url + "/"; services.AddHttpClient(desc.Key, client => { client.BaseAddress = new Uri(normUrl); }); } }
/// <summary> /// Integrates ApiClient factoring /// </summary> public static IServiceCollection AddApiClients( this IServiceCollection services, Action <IApiContractRegistrar> contractRegistration, ApiClientsOptions options) { if (services == null) { throw new ArgumentNullException(nameof(services)); } if (options == null) { throw new ArgumentNullException(nameof(options)); } HttpClientRegistrar.Register(services, options); if (contractRegistration != null) { var contractRegistrar = new DefaultApiContractRegistrar(services); contractRegistration(contractRegistrar); } return(services); }