feat(options): eager startup validation for site-pipeline options (SiteRuntime, S&F, SiteEventLog) (arch-review 08 §1.5)

Claude-Session: https://claude.ai/code/session_01MtdgwpEeCUn6cUA5f1LMPj
This commit is contained in:
Joseph Doherty
2026-07-10 06:51:05 -04:00
parent af2cfde484
commit 8b775f4ae1
10 changed files with 342 additions and 3 deletions
@@ -0,0 +1,35 @@
using ZB.MOM.WW.Configuration;
namespace ZB.MOM.WW.ScadaBridge.StoreAndForward;
/// <summary>
/// Validates <see cref="StoreAndForwardOptions"/> at startup. The retry intervals
/// feed the background sweep timer (a zero/negative period trips
/// <see cref="ArgumentOutOfRangeException"/> in the timer constructor) and the
/// SQLite path is opened for the S&amp;F buffer; an empty path yields an opaque
/// connection failure at first enqueue. Registered with <c>ValidateOnStart()</c>
/// so a bad <c>ScadaBridge:StoreAndForward</c> section fails fast at boot with a
/// clear, key-naming message.
/// </summary>
public sealed class StoreAndForwardOptionsValidator : OptionsValidatorBase<StoreAndForwardOptions>
{
/// <inheritdoc />
protected override void Validate(ValidationBuilder builder, StoreAndForwardOptions options)
{
builder.RequireThat(!string.IsNullOrWhiteSpace(options.SqliteDbPath),
"ScadaBridge:StoreAndForward:SqliteDbPath must be a non-empty path; " +
"it is the SQLite file backing the store-and-forward buffer.");
builder.RequireThat(options.DefaultRetryInterval > TimeSpan.Zero,
$"ScadaBridge:StoreAndForward:DefaultRetryInterval must be a positive duration " +
$"(was {options.DefaultRetryInterval}); it is the default per-message retry interval.");
builder.RequireThat(options.RetryTimerInterval > TimeSpan.Zero,
$"ScadaBridge:StoreAndForward:RetryTimerInterval must be a positive duration " +
$"(was {options.RetryTimerInterval}); it is the background retry-sweep timer period.");
builder.RequireThat(options.DefaultMaxRetries >= 0,
$"ScadaBridge:StoreAndForward:DefaultMaxRetries must be >= 0 " +
$"(was {options.DefaultMaxRetries}).");
}
}
@@ -13,6 +13,7 @@
<PackageReference Include="Microsoft.Extensions.DependencyInjection.Abstractions" />
<PackageReference Include="Microsoft.Extensions.Logging.Abstractions" />
<PackageReference Include="Microsoft.Extensions.Options" />
<PackageReference Include="ZB.MOM.WW.Configuration" />
</ItemGroup>
<ItemGroup>