using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.DependencyInjection.Extensions;
using Microsoft.Extensions.Options;
using ZB.MOM.WW.ScadaBridge.NotificationService.Ews;
namespace ZB.MOM.WW.ScadaBridge.NotificationService;
public static class ServiceCollectionExtensions
{
///
/// Registers the shared email delivery primitives consumed by the central Notification
/// Outbox's EmailNotificationDeliveryAdapter: ,
/// , the factory, and —
/// for the EWS transport — with its named HTTP client.
/// Central-only — sites no longer deliver notifications (see
/// Component-NotificationService.md), and the orphaned site-shaped
/// NotificationDeliveryService + INotificationDeliveryService contract
/// was removed. Notification dispatch lives in ZB.MOM.WW.ScadaBridge.NotificationOutbox.
///
/// The service collection to register into.
/// The same collection, for chaining.
public static IServiceCollection AddNotificationService(this IServiceCollection services)
{
services.AddOptions()
.BindConfiguration("ScadaBridge:Notification")
.ValidateOnStart();
services.TryAddEnumerable(
ServiceDescriptor.Singleton,
NotificationOptionsValidator>());
services.AddHttpClient();
services.AddSingleton();
services.AddSingleton>(_ => () => new MailKitSmtpClientWrapper());
// EWS transport: a named client so the EWS calls get their own handler pool, and a
// stateless singleton sender (credentials travel per request, never on the client).
services.AddHttpClient(EwsSoapMailSender.HttpClientName);
services.TryAddSingleton();
return services;
}
///
/// Registers Akka.NET actors for the notification service (placeholder for actor registration).
///
/// The service collection to register into.
/// The same collection, for chaining.
public static IServiceCollection AddNotificationServiceActors(this IServiceCollection services)
{
// Actor registration happens in AkkaHostedService.
return services;
}
}