mirror of
https://github.com/collinbarrett/FilterLists.git
synced 2026-03-11 09:04:27 +00:00
tidy AgentHttpClient registration and extract interface
This commit is contained in:
parent
56f7b4e647
commit
14d8e41924
7 changed files with 30 additions and 19 deletions
|
|
@ -1,4 +1,7 @@
|
|||
<wpf:ResourceDictionary xml:space="preserve" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:s="clr-namespace:System;assembly=mscorlib" xmlns:ss="urn:shemas-jetbrains-com:settings-storage-xaml" xmlns:wpf="http://schemas.microsoft.com/winfx/2006/xaml/presentation">
|
||||
<wpf:ResourceDictionary xml:space="preserve" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||
xmlns:s="clr-namespace:System;assembly=mscorlib"
|
||||
xmlns:ss="urn:shemas-jetbrains-com:settings-storage-xaml"
|
||||
xmlns:wpf="http://schemas.microsoft.com/winfx/2006/xaml/presentation">
|
||||
<s:String x:Key="/Default/CodeInspection/ExcludedFiles/FilesAndFoldersToSkip2/=6B3E6765_002D5B8B_002D4A23_002DAD12_002D7E2BC5F4D2E6_002Fd_003Awwwroot_002Fd_003Adist/@EntryIndexedValue">ExplicitlyExcluded</s:String>
|
||||
<s:String x:Key="/Default/CodeInspection/GeneratedCode/GeneratedFileMasks/=_002A_002EDesigner_002Ecs/@EntryIndexedValue"></s:String>
|
||||
<s:Boolean x:Key="/Default/CodeInspection/GeneratedCode/GeneratedFileMasks/=_002A_002EDesigner_002Ecs/@EntryIndexRemoved">True</s:Boolean>
|
||||
|
|
|
|||
|
|
@ -18,11 +18,7 @@ public static void RegisterAgentServices(this IServiceCollection services)
|
|||
services.AddConfiguration();
|
||||
services.AddLoggingCustom();
|
||||
services.AddMediatR(typeof(Program).Assembly);
|
||||
services.AddHttpClient<AgentHttpClient>().ConfigureHttpMessageHandlerBuilder(b =>
|
||||
{
|
||||
b.PrimaryHandler = new HttpClientHandler {AllowAutoRedirect = false};
|
||||
b.Build();
|
||||
});
|
||||
services.AddAgentHttpClient();
|
||||
services.AddSingleton<IFilterListsApiClient, FilterListsApiClient>();
|
||||
services.AddSingleton<IAgentGitHubClient, AgentGitHubClient>();
|
||||
services.AddTransient<IListInfoRepository, ListInfoRepository>();
|
||||
|
|
@ -43,6 +39,15 @@ private static void AddConfiguration(this IServiceCollection services)
|
|||
services.Configure<GitHub>(config.GetSection(nameof(GitHub)));
|
||||
}
|
||||
|
||||
private static void AddAgentHttpClient(this IServiceCollection services)
|
||||
{
|
||||
services.AddHttpClient<IAgentHttpClient, AgentHttpClient>().ConfigureHttpMessageHandlerBuilder(b =>
|
||||
{
|
||||
b.PrimaryHandler = new HttpClientHandler {AllowAutoRedirect = false};
|
||||
b.Build();
|
||||
});
|
||||
}
|
||||
|
||||
private static void AddLoggingCustom(this IServiceCollection services)
|
||||
{
|
||||
services.AddLogging(b =>
|
||||
|
|
|
|||
|
|
@ -30,9 +30,9 @@ public class Handler : AsyncRequestHandler<Command>
|
|||
private readonly HttpClient _httpClient;
|
||||
private readonly ILogger<Handler> _logger;
|
||||
|
||||
public Handler(AgentHttpClient agentHttpClient, ILogger<Handler> logger)
|
||||
public Handler(IAgentHttpClient agentHttpClient, ILogger<Handler> logger)
|
||||
{
|
||||
_httpClient = agentHttpClient.Client;
|
||||
_httpClient = agentHttpClient.HttpClient;
|
||||
_logger = logger;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -30,9 +30,9 @@ public class Handler : AsyncRequestHandler<Command>
|
|||
private readonly HttpClient _httpClient;
|
||||
private readonly ILogger<Handler> _logger;
|
||||
|
||||
public Handler(AgentHttpClient agentHttpClient, ILogger<Handler> logger)
|
||||
public Handler(IAgentHttpClient agentHttpClient, ILogger<Handler> logger)
|
||||
{
|
||||
_httpClient = agentHttpClient.Client;
|
||||
_httpClient = agentHttpClient.HttpClient;
|
||||
_logger = logger;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -29,9 +29,9 @@ public class Handler : AsyncRequestHandler<Command>
|
|||
private readonly HttpClient _httpClient;
|
||||
private readonly ILogger<Handler> _logger;
|
||||
|
||||
public Handler(AgentHttpClient agentHttpClient, ILogger<Handler> logger)
|
||||
public Handler(IAgentHttpClient agentHttpClient, ILogger<Handler> logger)
|
||||
{
|
||||
_httpClient = agentHttpClient.Client;
|
||||
_httpClient = agentHttpClient.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(AgentHttpClient agentHttpClient, ILogger<Handler> logger)
|
||||
public Handler(IAgentHttpClient agentHttpClient, ILogger<Handler> logger)
|
||||
{
|
||||
_httpClient = agentHttpClient.Client;
|
||||
_httpClient = agentHttpClient.HttpClient;
|
||||
_logger = logger;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1,12 +1,15 @@
|
|||
using System;
|
||||
using System.Net.Http;
|
||||
using System.Net.Http.Headers;
|
||||
using JetBrains.Annotations;
|
||||
|
||||
namespace FilterLists.Agent.Infrastructure.Clients
|
||||
{
|
||||
[UsedImplicitly]
|
||||
public class AgentHttpClient
|
||||
public interface IAgentHttpClient
|
||||
{
|
||||
HttpClient HttpClient { get; }
|
||||
}
|
||||
|
||||
public class AgentHttpClient : IAgentHttpClient
|
||||
{
|
||||
public AgentHttpClient(HttpClient client)
|
||||
{
|
||||
|
|
@ -16,9 +19,9 @@ public AgentHttpClient(HttpClient client)
|
|||
var userAgent = new ProductInfoHeaderValue(header);
|
||||
client.DefaultRequestHeaders.UserAgent.Add(userAgent);
|
||||
|
||||
Client = client;
|
||||
HttpClient = client;
|
||||
}
|
||||
|
||||
public HttpClient Client { get; }
|
||||
public HttpClient HttpClient { get; }
|
||||
}
|
||||
}
|
||||
Loading…
Reference in a new issue