itfx/src/InterfaceForward.Application/InterfaceForwardApplicationModule.cs

62 lines
2.5 KiB
C#
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

using System.Security.Authentication;
using Fake.AspNetCore;
using Fake.EventBus.RabbitMQ;
using Fake.Modularity;
using Fake.ObjectMapping.AutoMapper;
using Fake.RabbitMQ;
using FreeRedis;
using InterfaceForward.Application.Contracts;
using InterfaceForward.Application.Helpers;
using InterfaceForward.Application.HostServices;
using InterfaceForward.Domain.Shared;
using InterfaceForward.Repositories;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
namespace InterfaceForward.Application;
[DependsOn(typeof(FakeRabbitMqModule))]
[DependsOn(typeof(FakeAspNetCoreModule))]
[DependsOn(typeof(FakeObjectMappingAutoMapperModule))]
[DependsOn(typeof(FakeEventBusRabbitMqModule))]
[DependsOn(typeof(InterfaceForwardRepositoriesModule))]
[DependsOn(typeof(InterfaceForwardDomainSharedModule))]
public class InterfaceForwardApplicationModule:FakeModule
{
public override void ConfigureServices(ServiceConfigurationContext context)
{
var configuration = context.Services.GetConfiguration();
context.Services.Configure<FakeAutoMapperOptions>(options =>
{
options.ScanProfiles<InterfaceForwardApplicationModule>();
});
context.Services.Configure<InterfaceRelayOptions>(configuration.GetSection("InterfaceRelay"));
context.Services.AddHostedService<AppSubscribeHostService>();
var options = configuration.GetSection("Redis").Get<ConnectionStringBuilder>();
if (options == null)
throw new FakeException("未找到Redis相关配置请检查配置文件中是否包含名为Redis的节点");
RedisHelper.Init(options, showLogInfo: System.Diagnostics.Debugger.IsAttached);
// 预热
NatashaInitializer.Preheating();
context.Services.AddHttpClient("forward", client =>
{
client.Timeout = TimeSpan.FromSeconds(20);
})
.ConfigurePrimaryHttpMessageHandler(_ =>
{
var httpClientHandler = new HttpClientHandler();
// 确保支持较新的 SSL/TLS 版本
httpClientHandler.SslProtocols = SslProtocols.Tls12 | SslProtocols.Tls13;
// 忽略 SSL/TLS 证书错误
httpClientHandler.ServerCertificateCustomValidationCallback =
HttpClientHandler.DangerousAcceptAnyServerCertificateValidator;
return httpClientHandler;
});
}
}