using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Options; using ZB.MOM.WW.ScadaBridge.Commons.Types.InboundApi; namespace ZB.MOM.WW.ScadaBridge.InboundAPI; public static class ServiceCollectionExtensions { /// /// Registers all inbound API services (API key validator, script executor, route helper, and endpoint filter). /// /// The service collection to register into. public static IServiceCollection AddInboundAPI(this IServiceCollection services) { services.AddScoped(); services.AddSingleton(); services.AddScoped(); // ConfigurationDatabase-012: API keys are persisted as a deterministic HMAC // hash, never as plaintext. The hasher is keyed with a server-side pepper // bound from configuration (InboundApiOptions.ApiKeyPepper). Constructing // ApiKeyHasher throws if the pepper is missing or weak — so a misconfigured // deployment fails fast the first time the hasher is resolved rather than // silently hashing with no pepper. services.AddSingleton(sp => { var options = sp.GetRequiredService>().Value; return new ApiKeyHasher(options.ApiKeyPepper); }); // InboundAPI-017: routed calls go through the IInstanceRouter seam; the // production implementation delegates to CommunicationService. services.AddScoped(); // InboundAPI-006 / InboundAPI-008: endpoint filter enforcing the request // body size cap and active-node gating for POST /api/{methodName}. services.AddSingleton(); return services; } }