using System.Net.Http;
using Dpz.Core.Hangfire;
using Dpz.Core.Service.Network;
using Dpz.Core.Service.ObjectStorage;
using Dpz.Core.Web.Library.Api;
using Dpz.Core.Web.Library.Api.Service;
using MailKit;
namespace Dpz.Core.Web.Library;
public static class DependencyInjectionExtensions
{
public static IServiceCollection AddInject(this IServiceCollection services)
{
services.AddHttpContextAccessor();
services.AddShardCloudFileService();
services.AddScoped<IHomeCacheService, HomeCacheService>();
services.AddScoped<IApplicationSignInManager, ApplicationSignInManager>();
services.AddScoped<IUserClaimsPrincipalFactory<VmUserInfo>, UserInfoClaimsPrincipalFactory>();
services.AddScoped<IChatCurrentUserService, ChatCurrentUserService>();
services.AddTransient<IProtocolLogger, SerilogProtocolLogger>();
services.AddHttpClient();
services.AddHttpClient("edge",
httpClient => { httpClient.DefaultRequestHeaders.Add("User-Agent", EnvironmentInfo.UserAgent); })
.ConfigurePrimaryHttpMessageHandler(_ => new HttpClientHandler
{
ServerCertificateCustomValidationCallback = (_, _, _, _) => true
});
services.AddHttpClient("WebAPI",
(sp, httpClient) =>
{
var configuration = sp.GetService<IConfiguration>();
var apiAddress = configuration?["WebApi"] ?? throw new Exception("web api address is null");
httpClient.BaseAddress = new Uri(apiAddress);
})
.ConfigurePrimaryHttpMessageHandler(_ => new HttpClientHandler
{
ServerCertificateCustomValidationCallback = (_, _, _, _) => true
});
//添加 又拍云储存
services.AddUpyunObjectStorage();
services.AddNetworkServices();
//Steam API
services.AddHttpClient<ISteamGameService, SteamGameService>((sp, client) =>
{
ActivatorUtilities.CreateInstance<SteamGameService>(sp);
client.BaseAddress = new Uri("https://api.steampowered.com");
}).ConfigurePrimaryHttpMessageHandler(_ => new HttpClientHandler
{
ServerCertificateCustomValidationCallback = (_, _, _, _) => true
});
return services;
}
}