using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Options; using ScadaLink.Commons.Interfaces.Services; namespace ScadaLink.ExternalSystemGateway; public static class ServiceCollectionExtensions { public static IServiceCollection AddExternalSystemGateway(this IServiceCollection services) { services.AddOptions() .BindConfiguration("ScadaLink:ExternalSystemGateway"); services.AddHttpClient(); // ExternalSystemGateway-013: wire MaxConcurrentConnectionsPerSystem into the // primary handler of every per-system named client ("ExternalSystem_{name}"), // so the option an operator configures actually bounds concurrent connections // instead of being silently ignored. ConfigureHttpClientDefaults applies to // the dynamically-named clients created by ExternalSystemClient. services.ConfigureHttpClientDefaults(builder => builder.ConfigurePrimaryHttpMessageHandler(sp => { var options = sp.GetRequiredService>().Value; return new SocketsHttpHandler { MaxConnectionsPerServer = options.MaxConcurrentConnectionsPerSystem, }; })); services.AddScoped(); services.AddScoped(sp => sp.GetRequiredService()); services.AddScoped(); services.AddScoped(sp => sp.GetRequiredService()); return services; } public static IServiceCollection AddExternalSystemGatewayActors(this IServiceCollection services) { // WP-10: Actor registration happens in AkkaHostedService. // Script Execution Actors run on dedicated blocking I/O dispatcher. return services; } }