ren HttpClient -> Factory

This commit is contained in:
Collin M. Barrett 2019-07-07 15:29:13 -05:00
parent c673b85486
commit 84cef36388
7 changed files with 20 additions and 18 deletions

View file

@ -2,7 +2,7 @@
namespace FilterLists.Agent.Core.Interfaces.Clients
{
public interface IAgentHttpClient
public interface IAgentHttpClientFactory
{
HttpClient HttpClient { get; }
}

View file

@ -74,13 +74,15 @@ private static void AddLoggingCustom(this IServiceCollection services)
private static void AddAgentHttpClient(this IServiceCollection services)
{
services.AddHttpClient<IAgentHttpClient, AgentHttpClient>().ConfigureHttpMessageHandlerBuilder(b =>
{
b.PrimaryHandler = new HttpClientHandler {AllowAutoRedirect = false};
b.Build();
}).AddTransientHttpErrorPolicy(b =>
b.OrResult(r => r.StatusCode == HttpStatusCode.TooManyRequests)
.WaitAndRetryAsync(5, i => i * TimeSpan.FromSeconds(3)));
services.AddHttpClient<IAgentHttpClientFactory, AgentHttpClientFactory>()
.ConfigureHttpMessageHandlerBuilder(b =>
{
b.PrimaryHandler = new HttpClientHandler {AllowAutoRedirect = false};
b.Build();
})
.AddTransientHttpErrorPolicy(b =>
b.OrResult(r => r.StatusCode == HttpStatusCode.TooManyRequests)
.WaitAndRetryAsync(5, i => i * TimeSpan.FromSeconds(3)));
}
private static void AddGitHubClient(this IServiceCollection services)

View file

@ -30,9 +30,9 @@ public class Handler : AsyncRequestHandler<Command>
private readonly HttpClient _httpClient;
private readonly ILogger<Handler> _logger;
public Handler(IAgentHttpClient agentHttpClient, ILogger<Handler> logger)
public Handler(IAgentHttpClientFactory agentHttpClientFactory, ILogger<Handler> logger)
{
_httpClient = agentHttpClient.HttpClient;
_httpClient = agentHttpClientFactory.HttpClient;
_logger = logger;
}

View file

@ -30,9 +30,9 @@ public class Handler : AsyncRequestHandler<Command>
private readonly HttpClient _httpClient;
private readonly ILogger<Handler> _logger;
public Handler(IAgentHttpClient agentHttpClient, ILogger<Handler> logger)
public Handler(IAgentHttpClientFactory agentHttpClientFactory, ILogger<Handler> logger)
{
_httpClient = agentHttpClient.HttpClient;
_httpClient = agentHttpClientFactory.HttpClient;
_logger = logger;
}

View file

@ -29,9 +29,9 @@ public class Handler : AsyncRequestHandler<Command>
private readonly HttpClient _httpClient;
private readonly ILogger<Handler> _logger;
public Handler(IAgentHttpClient agentHttpClient, ILogger<Handler> logger)
public Handler(IAgentHttpClientFactory agentHttpClientFactory, ILogger<Handler> logger)
{
_httpClient = agentHttpClient.HttpClient;
_httpClient = agentHttpClientFactory.HttpClient;
_logger = logger;
}

View file

@ -31,9 +31,9 @@ public class Handler : IRequestHandler<Command, List<UrlValidationResult>>
private readonly HttpClient _httpClient;
private readonly ILogger<Handler> _logger;
public Handler(IAgentHttpClient agentHttpClient, ILogger<Handler> logger)
public Handler(IAgentHttpClientFactory agentHttpClientFactory, ILogger<Handler> logger)
{
_httpClient = agentHttpClient.HttpClient;
_httpClient = agentHttpClientFactory.HttpClient;
_logger = logger;
}

View file

@ -7,9 +7,9 @@
namespace FilterLists.Agent.Infrastructure.Clients
{
[UsedImplicitly]
public class AgentHttpClient : IAgentHttpClient
public class AgentHttpClientFactory : IAgentHttpClientFactory
{
public AgentHttpClient(HttpClient client)
public AgentHttpClientFactory(HttpClient client)
{
client.Timeout = TimeSpan.FromSeconds(90);