mirror of
https://github.com/collinbarrett/FilterLists.git
synced 2026-03-11 09:04:27 +00:00
ren HttpClient -> Factory
This commit is contained in:
parent
c673b85486
commit
84cef36388
7 changed files with 20 additions and 18 deletions
|
|
@ -2,7 +2,7 @@
|
|||
|
||||
namespace FilterLists.Agent.Core.Interfaces.Clients
|
||||
{
|
||||
public interface IAgentHttpClient
|
||||
public interface IAgentHttpClientFactory
|
||||
{
|
||||
HttpClient HttpClient { get; }
|
||||
}
|
||||
|
|
@ -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)
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
|
||||
Loading…
Reference in a new issue