HttpClientInstaller.cs
1.24 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Rcs.Application.Shared;
using Rcs.Cyaninetech.BackgroundServices;
using Rcs.Cyaninetech.Services;
using Rcs.Infrastructure.Shared;
namespace Rcs.Infrastructure.Installs;
/// <summary>
/// LanYin外挂服务安装器
/// </summary>
public static class HttpClientInstaller
{
/// <summary>
/// 安装HttpClient服务
/// </summary>
public static IServiceCollection InstallHttpClient(
this IServiceCollection services)
{
// 注册通用HTTP客户端服务(如果尚未注册)
if (!services.Any(x => x.ServiceType == typeof(IHttpClientService)))
{
services.AddHttpClient<IHttpClientService, HttpClientService>()
.ConfigureHttpClient(client =>
{
client.Timeout = TimeSpan.FromSeconds(30);
})
.ConfigurePrimaryHttpMessageHandler(() =>
{
return new HttpClientHandler
{
ServerCertificateCustomValidationCallback = (message, cert, chain, errors) => true
};
});
}
return services;
}
}