using JSMR.Application.Circles.Queries.GetCreators; using JSMR.Application.Circles.Queries.GetTags; using JSMR.Application.Circles.Queries.Search; using JSMR.Application.Common.Caching; using JSMR.Application.Creators.Ports; using JSMR.Application.Creators.Queries.Search.Ports; using JSMR.Application.Enums; using JSMR.Application.Integrations.Ports; using JSMR.Application.Scanning.Ports; using JSMR.Application.Tags.Ports; using JSMR.Application.Tags.Queries.Search.Ports; using JSMR.Application.VoiceWorks.Ports; using JSMR.Application.VoiceWorks.Queries.Search; using JSMR.Infrastructure.Caching; using JSMR.Infrastructure.Caching.Adapters; using JSMR.Infrastructure.Common.Languages; using JSMR.Infrastructure.Common.SupportedLanguages; using JSMR.Infrastructure.Common.Time; using JSMR.Infrastructure.Data.Repositories.Circles; using JSMR.Infrastructure.Data.Repositories.Creators; using JSMR.Infrastructure.Data.Repositories.Tags; using JSMR.Infrastructure.Data.Repositories.VoiceWorks; using JSMR.Infrastructure.Http; using JSMR.Infrastructure.Ingestion; using JSMR.Infrastructure.Integrations.DLSite; using JSMR.Infrastructure.Scanning; using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Http.Resilience; using Polly; using System.Net; namespace JSMR.Infrastructure.DI; public static class InfrastructureServiceCollectionExtensions { public static IServiceCollection AddInfrastructure(this IServiceCollection services) { services.AddScoped(); services.AddScoped(); services.AddScoped(); services.AddScoped(); services.AddScoped(); services.AddScoped(); services.AddKeyedScoped(Locale.Japanese); services.AddKeyedScoped(Locale.English); services.AddKeyedScoped(Locale.Japanese); services.AddKeyedScoped(Locale.English); services.AddScoped(); //services.AddKeyedScoped(Locale.Japanese); //services.AddKeyedScoped(Locale.English); //services.AddKeyedScoped(Locale.ChineseSimplified); //services.AddKeyedScoped(Locale.ChineseTraditional); //services.AddKeyedScoped(Locale.Korean); services.AddScoped(); services.AddScoped(); services.AddScoped(); services.AddScoped(); services.AddSingleton(); services.AddSingleton(); services.AddSingleton(); services.AddSingleton(); services.AddSingleton(); services.AddHttpServices(); return services; } private static IServiceCollection AddHttpServices(this IServiceCollection services) { //services.AddHttpClient(client => //{ // client.DefaultRequestHeaders.UserAgent.ParseAdd("JSMR/1.0"); //}); //services.AddScoped(); services.AddScoped(); // ONE registration for IHttpService as a typed client: services.AddHttpClient((sp, http) => { http.BaseAddress = new Uri("https://www.dlsite.com/"); http.DefaultRequestHeaders.UserAgent.ParseAdd("JSMR/1.0"); http.Timeout = TimeSpan.FromSeconds(15); }) .AddResilienceHandler("dlsite", builder => { builder.AddRetry(new HttpRetryStrategyOptions { MaxRetryAttempts = 3, UseJitter = true, Delay = TimeSpan.FromMilliseconds(200), BackoffType = DelayBackoffType.Exponential, ShouldHandle = new PredicateBuilder() .Handle() .HandleResult(r => (int)r.StatusCode >= 500 || (int)r.StatusCode == 429) }); }); // Register DLSiteClient as a normal scoped service services.AddScoped(); return services; } }