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:
@@ -0,0 +1,30 @@
|
||||
using ZB.MOM.WW.Configuration;
|
||||
|
||||
namespace ZB.MOM.WW.ScadaBridge.ManagementService;
|
||||
|
||||
/// <summary>
|
||||
/// Validates <see cref="ManagementServiceOptions"/> at startup. Both
|
||||
/// <see cref="ManagementServiceOptions.CommandTimeout"/> and
|
||||
/// <see cref="ManagementServiceOptions.LongRunningCommandTimeout"/> are used as Ask timeouts against
|
||||
/// the ManagementActor; a zero/negative value makes every management command fail immediately (or Ask
|
||||
/// forever). Registered with <c>ValidateOnStart()</c> so a bad <c>ScadaBridge:ManagementService</c>
|
||||
/// section fails fast at boot with a clear, key-naming message.
|
||||
/// <para>
|
||||
/// <see cref="ManagementServiceOptions.SecuredWritePendingTtl"/> is intentionally NOT required positive:
|
||||
/// a non-positive value legitimately disables server-side secured-write expiry.
|
||||
/// </para>
|
||||
/// </summary>
|
||||
public sealed class ManagementServiceOptionsValidator : OptionsValidatorBase<ManagementServiceOptions>
|
||||
{
|
||||
/// <inheritdoc />
|
||||
protected override void Validate(ValidationBuilder builder, ManagementServiceOptions options)
|
||||
{
|
||||
builder.RequireThat(options.CommandTimeout > TimeSpan.Zero,
|
||||
$"ScadaBridge:ManagementService:CommandTimeout must be a positive duration " +
|
||||
$"(was {options.CommandTimeout}); it is the Ask timeout for management commands.");
|
||||
|
||||
builder.RequireThat(options.LongRunningCommandTimeout > TimeSpan.Zero,
|
||||
$"ScadaBridge:ManagementService:LongRunningCommandTimeout must be a positive duration " +
|
||||
$"(was {options.LongRunningCommandTimeout}); it is the Ask timeout for transport/deploy commands.");
|
||||
}
|
||||
}
|
||||
@@ -1,4 +1,6 @@
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Microsoft.Extensions.DependencyInjection.Extensions;
|
||||
using Microsoft.Extensions.Options;
|
||||
|
||||
namespace ZB.MOM.WW.ScadaBridge.ManagementService;
|
||||
|
||||
@@ -13,7 +15,11 @@ public static class ServiceCollectionExtensions
|
||||
{
|
||||
services.AddSingleton<ManagementActorHolder>();
|
||||
services.AddOptions<ManagementServiceOptions>()
|
||||
.BindConfiguration("ScadaBridge:ManagementService");
|
||||
.BindConfiguration("ScadaBridge:ManagementService")
|
||||
.ValidateOnStart();
|
||||
services.TryAddEnumerable(
|
||||
ServiceDescriptor.Singleton<IValidateOptions<ManagementServiceOptions>,
|
||||
ManagementServiceOptionsValidator>());
|
||||
return services;
|
||||
}
|
||||
}
|
||||
|
||||
+1
@@ -14,6 +14,7 @@
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Akka" />
|
||||
<PackageReference Include="Akka.Cluster.Tools" />
|
||||
<PackageReference Include="ZB.MOM.WW.Configuration" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="../ZB.MOM.WW.ScadaBridge.Commons/ZB.MOM.WW.ScadaBridge.Commons.csproj" />
|
||||
|
||||
Reference in New Issue
Block a user