feat(options): eager startup validation for edge/management options (InboundAPI, ESG, Notification, ManagementService) (arch-review 08 §1.5)
Claude-Session: https://claude.ai/code/session_01MtdgwpEeCUn6cUA5f1LMPj
This commit is contained in:
+33
@@ -0,0 +1,33 @@
|
||||
using ZB.MOM.WW.Configuration;
|
||||
|
||||
namespace ZB.MOM.WW.ScadaBridge.ExternalSystemGateway;
|
||||
|
||||
/// <summary>
|
||||
/// Validates <see cref="ExternalSystemGatewayOptions"/> at startup.
|
||||
/// <see cref="ExternalSystemGatewayOptions.DefaultHttpTimeout"/> bounds each outbound call,
|
||||
/// <see cref="ExternalSystemGatewayOptions.MaxConcurrentConnectionsPerSystem"/> is fed into
|
||||
/// <c>SocketsHttpHandler.MaxConnectionsPerServer</c> (a non-positive value throws in the handler
|
||||
/// constructor), and <see cref="ExternalSystemGatewayOptions.MaxResponseBodyBytes"/> caps buffered
|
||||
/// response bodies. Registered with <c>ValidateOnStart()</c> so a bad
|
||||
/// <c>ScadaBridge:ExternalSystemGateway</c> section fails fast at boot with a clear, key-naming
|
||||
/// message rather than crashing the HTTP client factory or silently disabling the gateway.
|
||||
/// </summary>
|
||||
public sealed class ExternalSystemGatewayOptionsValidator : OptionsValidatorBase<ExternalSystemGatewayOptions>
|
||||
{
|
||||
/// <inheritdoc />
|
||||
protected override void Validate(ValidationBuilder builder, ExternalSystemGatewayOptions options)
|
||||
{
|
||||
builder.RequireThat(options.DefaultHttpTimeout > TimeSpan.Zero,
|
||||
$"ScadaBridge:ExternalSystemGateway:DefaultHttpTimeout must be a positive duration " +
|
||||
$"(was {options.DefaultHttpTimeout}); it bounds each outbound external-system HTTP call.");
|
||||
|
||||
builder.RequireThat(options.MaxConcurrentConnectionsPerSystem > 0,
|
||||
$"ScadaBridge:ExternalSystemGateway:MaxConcurrentConnectionsPerSystem must be greater than zero " +
|
||||
$"(was {options.MaxConcurrentConnectionsPerSystem}); it is fed into " +
|
||||
"SocketsHttpHandler.MaxConnectionsPerServer, which rejects non-positive values.");
|
||||
|
||||
builder.RequireThat(options.MaxResponseBodyBytes > 0,
|
||||
$"ScadaBridge:ExternalSystemGateway:MaxResponseBodyBytes must be greater than zero " +
|
||||
$"(was {options.MaxResponseBodyBytes}); it caps the outbound response body buffered into memory.");
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user