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:
Joseph Doherty
2026-07-10 06:52:59 -04:00
parent 8b775f4ae1
commit fc918d4679
16 changed files with 404 additions and 4 deletions
@@ -0,0 +1,27 @@
using ZB.MOM.WW.Configuration;
namespace ZB.MOM.WW.ScadaBridge.NotificationService;
/// <summary>
/// Validates <see cref="NotificationOptions"/> at startup. The values are the SMTP fallback used
/// by the central Email delivery adapter when the deployed <c>SmtpConfiguration</c> leaves the
/// corresponding field unset: <see cref="NotificationOptions.ConnectionTimeoutSeconds"/> becomes an
/// SMTP connect timeout and <see cref="NotificationOptions.MaxConcurrentConnections"/> caps the
/// connection pool — a non-positive value there is not a usable fallback. Registered with
/// <c>ValidateOnStart()</c> so a bad <c>ScadaBridge:Notification</c> section fails fast at boot with
/// a clear, key-naming message.
/// </summary>
public sealed class NotificationOptionsValidator : OptionsValidatorBase<NotificationOptions>
{
/// <inheritdoc />
protected override void Validate(ValidationBuilder builder, NotificationOptions options)
{
builder.RequireThat(options.ConnectionTimeoutSeconds > 0,
$"ScadaBridge:Notification:ConnectionTimeoutSeconds must be greater than zero " +
$"(was {options.ConnectionTimeoutSeconds}); it is the SMTP connect-timeout fallback.");
builder.RequireThat(options.MaxConcurrentConnections > 0,
$"ScadaBridge:Notification:MaxConcurrentConnections must be greater than zero " +
$"(was {options.MaxConcurrentConnections}); it caps the SMTP connection pool.");
}
}
@@ -1,4 +1,6 @@
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.DependencyInjection.Extensions;
using Microsoft.Extensions.Options;
namespace ZB.MOM.WW.ScadaBridge.NotificationService;
@@ -18,7 +20,11 @@ public static class ServiceCollectionExtensions
public static IServiceCollection AddNotificationService(this IServiceCollection services)
{
services.AddOptions<NotificationOptions>()
.BindConfiguration("ScadaBridge:Notification");
.BindConfiguration("ScadaBridge:Notification")
.ValidateOnStart();
services.TryAddEnumerable(
ServiceDescriptor.Singleton<IValidateOptions<NotificationOptions>,
NotificationOptionsValidator>());
services.AddHttpClient();
services.AddSingleton<OAuth2TokenService>();
@@ -13,6 +13,7 @@
<PackageReference Include="Microsoft.Extensions.Http" />
<PackageReference Include="Microsoft.Extensions.Logging.Abstractions" />
<PackageReference Include="Microsoft.Extensions.Options" />
<PackageReference Include="ZB.MOM.WW.Configuration" />
</ItemGroup>
<ItemGroup>