using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.DependencyInjection.Extensions;
using Microsoft.Extensions.Options;
namespace ZB.MOM.WW.ScadaBridge.DataConnectionLayer;
///
/// DI registration extensions for the Data Connection Layer.
///
public static class ServiceCollectionExtensions
{
/// Registers Data Connection Layer options and core services.
/// The DI service collection to register into.
/// The same instance for chaining.
public static IServiceCollection AddDataConnectionLayer(this IServiceCollection services)
{
// Canonical section is ScadaBridge:DataConnection — the section every real
// appsettings actually writes (arch-review 08 round 2 NF8). The Host used to
// supply the real values via a duplicate Configure<> binding; that duplicate is
// gone, so AddDataConnectionLayer must bind the canonical section itself.
services.AddOptions()
.BindConfiguration("ScadaBridge:DataConnection")
.ValidateOnStart();
services.TryAddEnumerable(
ServiceDescriptor.Singleton, DataConnectionOptionsValidator>());
// OpcUaGlobalOptions / MxGatewayGlobalOptions carry only string identity/path
// fields (no numeric or duration knobs), so there is nothing to range-validate
// — no dedicated validator is registered for them. Canonical sections are
// ScadaBridge:OpcUa / ScadaBridge:MxGateway (NF8): the bare "OpcUa"/"MxGateway"
// sections exist in no appsettings, so binding them read nothing.
services.AddOptions()
.BindConfiguration("ScadaBridge:OpcUa");
services.AddOptions()
.BindConfiguration("ScadaBridge:MxGateway");
// Register the factory for protocol extensibility
services.AddSingleton();
return services;
}
/// Placeholder for actor registration; Data Connection Layer actors are created inside the ActorSystem.
/// The DI service collection.
/// The same instance for chaining.
public static IServiceCollection AddDataConnectionLayerActors(this IServiceCollection services)
{
// Actor registration happens in AkkaHostedService or SiteCommunicationActor setup.
// DataConnectionManagerActor and DataConnectionActor instances are created by the actor system.
return services;
}
}