56 lines
2.7 KiB
C#
56 lines
2.7 KiB
C#
using Microsoft.Extensions.DependencyInjection;
|
|
using Microsoft.Extensions.DependencyInjection.Extensions;
|
|
using Microsoft.Extensions.Options;
|
|
|
|
namespace ZB.MOM.WW.ScadaBridge.DataConnectionLayer;
|
|
|
|
/// <summary>
|
|
/// DI registration extensions for the Data Connection Layer.
|
|
/// </summary>
|
|
public static class ServiceCollectionExtensions
|
|
{
|
|
/// <summary>Registers Data Connection Layer options and core services.</summary>
|
|
/// <param name="services">The DI service collection to register into.</param>
|
|
/// <returns>The same <paramref name="services"/> instance for chaining.</returns>
|
|
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<DataConnectionOptions>()
|
|
.BindConfiguration("ScadaBridge:DataConnection")
|
|
.ValidateOnStart();
|
|
services.TryAddEnumerable(
|
|
ServiceDescriptor.Singleton<IValidateOptions<DataConnectionOptions>, DataConnectionOptionsValidator>());
|
|
|
|
// Validate identities before the first connection attempts to register with a server.
|
|
services.AddOptions<OpcUaGlobalOptions>()
|
|
.BindConfiguration("ScadaBridge:OpcUa")
|
|
.ValidateOnStart();
|
|
services.TryAddEnumerable(
|
|
ServiceDescriptor.Singleton<IValidateOptions<OpcUaGlobalOptions>, OpcUaGlobalOptionsValidator>());
|
|
|
|
services.AddOptions<MxGatewayGlobalOptions>()
|
|
.BindConfiguration("ScadaBridge:MxGateway")
|
|
.ValidateOnStart();
|
|
services.TryAddEnumerable(
|
|
ServiceDescriptor.Singleton<IValidateOptions<MxGatewayGlobalOptions>, MxGatewayGlobalOptionsValidator>());
|
|
|
|
// Register the factory for protocol extensibility
|
|
services.AddSingleton<IDataConnectionFactory, DataConnectionFactory>();
|
|
|
|
return services;
|
|
}
|
|
|
|
/// <summary>Placeholder for actor registration; Data Connection Layer actors are created inside the ActorSystem.</summary>
|
|
/// <param name="services">The DI service collection.</param>
|
|
/// <returns>The same <paramref name="services"/> instance for chaining.</returns>
|
|
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;
|
|
}
|
|
}
|