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(options => { options.ScanProfiles(); }); context.Services.Configure(configuration.GetSection("InterfaceRelay")); context.Services.AddHostedService(); var options = configuration.GetSection("Redis").Get(); 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; }); } }