| | | 1 | | using Microsoft.Extensions.Logging; |
| | | 2 | | using Pomodoro.Web.Services; |
| | | 3 | | |
| | | 4 | | namespace Pomodoro.Web.Services; |
| | | 5 | | |
| | | 6 | | /// <summary> |
| | | 7 | | /// Service for wiring up event subscribers to timer events. |
| | | 8 | | /// Extracted from Program.cs for testability. |
| | | 9 | | /// </summary> |
| | | 10 | | public interface IEventWiringService |
| | | 11 | | { |
| | | 12 | | void WireEventSubscribers(IServiceProvider serviceProvider); |
| | | 13 | | } |
| | | 14 | | |
| | | 15 | | public class EventWiringService : IEventWiringService |
| | | 16 | | { |
| | | 17 | | private readonly ILogger<EventWiringService> _logger; |
| | | 18 | | |
| | 12 | 19 | | public EventWiringService(ILogger<EventWiringService> logger) |
| | 12 | 20 | | { |
| | 12 | 21 | | _logger = logger; |
| | 12 | 22 | | } |
| | | 23 | | |
| | | 24 | | public void WireEventSubscribers(IServiceProvider serviceProvider) |
| | 9 | 25 | | { |
| | | 26 | | // Get service references |
| | 9 | 27 | | var timerService = serviceProvider.GetRequiredService<ITimerService>(); |
| | 9 | 28 | | var taskService = serviceProvider.GetService<ITaskService>(); |
| | 9 | 29 | | var activityService = serviceProvider.GetService<IActivityService>(); |
| | | 30 | | |
| | | 31 | | // Wire up event subscribers to timer publisher |
| | 9 | 32 | | if (timerService is ITimerEventPublisher timerPublisher) |
| | 8 | 33 | | { |
| | | 34 | | // Subscribe TaskService to timer events |
| | 8 | 35 | | if (taskService is ITimerEventSubscriber taskSubscriber) |
| | 2 | 36 | | { |
| | 2 | 37 | | timerPublisher.OnTimerCompleted += taskSubscriber.HandleTimerCompletedAsync; |
| | 2 | 38 | | } |
| | | 39 | | |
| | | 40 | | // Subscribe ActivityService to timer events |
| | 8 | 41 | | if (activityService is ITimerEventSubscriber activitySubscriber) |
| | 2 | 42 | | { |
| | 2 | 43 | | timerPublisher.OnTimerCompleted += activitySubscriber.HandleTimerCompletedAsync; |
| | 2 | 44 | | } |
| | 8 | 45 | | } |
| | | 46 | | |
| | 9 | 47 | | _logger.LogInformation("Event subscribers wired up successfully"); |
| | 9 | 48 | | } |
| | | 49 | | } |