private static IServiceCollection AddMhHttpClient <TClient, TImplementation, TMessageHandler>(this IServiceCollection services, HttpOptions options = null) where TClient : class where TImplementation : class, TClient where TMessageHandler : DelegatingHandler { options = options ?? new HttpOptions(); var builder = CreateHttpBuilder <TClient, TImplementation, TMessageHandler>(services, options); ApplyPollyConfiguration <TClient, TMessageHandler>(options, builder); return(services); }
private static IHttpClientBuilder CreateHttpBuilder <TClient, TImplementation, TMessageHandler>(IServiceCollection services, HttpOptions options) where TClient : class where TImplementation : class, TClient where TMessageHandler : DelegatingHandler { return(services.AddHttpClient <TClient, TImplementation>(client => { client.BaseAddress = GetBaseUrl(options); }).AddHttpMessageHandler <TMessageHandler>() .SetHandlerLifetime(TimeSpan.FromMinutes(5))); }
public static IServiceCollection AddUnsignedHttpClient <TClient, TImplementation>(this IServiceCollection services, HttpOptions options = null) where TClient : class where TImplementation : class, TClient { services.AddTransient <BaseHttpMessageHandler>(); return(AddMhHttpClient <TClient, TImplementation, BaseHttpMessageHandler>(services, options)); }