using DbusSmsForward.Notifications; using DbusSmsForward.SMSModel; using Microsoft.Extensions.Logging; namespace DbusSmsForward.Services; public sealed class NotificationDispatcher(IEnumerable senders, ILogger logger) { private readonly IReadOnlyList _senders = senders.Where(static s => s.IsEnabled).ToList(); public async Task DispatchAsync(SmsContentModel sms, string body, string deviceName, CancellationToken cancellationToken) { foreach (INotificationSender sender in _senders) { try { await sender.SendAsync(sms, body, deviceName, cancellationToken); logger.LogInformation("Notification sender {Sender} completed for {PhoneNumber}", sender.Name, sms.TelNumber); } catch (Exception ex) { logger.LogError(ex, "Notification sender {Sender} failed for {PhoneNumber}", sender.Name, sms.TelNumber); } } } }