| | | 1 | | using Microsoft.Extensions.DependencyInjection; |
| | | 2 | | using Microsoft.Extensions.Logging; |
| | | 3 | | using Pomodoro.Web.Models; |
| | | 4 | | using Pomodoro.Web.Services.Formatters; |
| | | 5 | | using Pomodoro.Web.Services.Repositories; |
| | | 6 | | |
| | | 7 | | namespace Pomodoro.Web.Services; |
| | | 8 | | |
| | | 9 | | /// <summary> |
| | | 10 | | /// Service for re6gistering all application services with DI container. |
| | | 11 | | /// Extracted from Program.cs for testability. |
| | | 12 | | /// </summary> |
| | | 13 | | public interface IServiceRegistrationService |
| | | 14 | | { |
| | | 15 | | void RegisterServices(IServiceCollection services); |
| | | 16 | | } |
| | | 17 | | |
| | | 18 | | public class ServiceRegistrationService : IServiceRegistrationService |
| | | 19 | | { |
| | | 20 | | private readonly ILogger<ServiceRegistrationService>? _logger; |
| | | 21 | | |
| | 31 | 22 | | public ServiceRegistrationService(ILogger<ServiceRegistrationService>? logger = null) |
| | 31 | 23 | | { |
| | 31 | 24 | | _logger = logger; |
| | 31 | 25 | | } |
| | | 26 | | |
| | | 27 | | public void RegisterServices(IServiceCollection services) |
| | 28 | 28 | | { |
| | | 29 | | // Register AppState as singleton-like scoped service |
| | 28 | 30 | | services.AddScoped<AppState>(); |
| | | 31 | | |
| | | 32 | | // Register IndexedDB service (must be registered before services that depend on it) |
| | 28 | 33 | | services.AddScoped<IIndexedDbService, IndexedDbService>(); |
| | | 34 | | |
| | | 35 | | // Register repositories (must be registered before services that depend on them) |
| | 28 | 36 | | services.AddScoped<ITaskRepository, TaskRepository>(); |
| | 28 | 37 | | services.AddScoped<IActivityRepository, ActivityRepository>(); |
| | 28 | 38 | | services.AddScoped<ISettingsRepository, SettingsRepository>(); |
| | | 39 | | |
| | | 40 | | // Register services that use repositories and implement ITimerEventSubscriber |
| | 28 | 41 | | services.AddScoped<ITaskService, TaskService>(); |
| | 28 | 42 | | services.AddScoped<IActivityService, ActivityService>(); |
| | 28 | 43 | | services.AddScoped<ITimerService, TimerService>(); |
| | 28 | 44 | | services.AddScoped<ISessionOptionsService, SessionOptionsService>(); |
| | 28 | 45 | | services.AddScoped<IConsentService, ConsentService>(); |
| | 28 | 46 | | services.AddScoped<INotificationService, NotificationService>(); |
| | 28 | 47 | | services.AddScoped<IPipTimerService, PipTimerService>(); |
| | 28 | 48 | | services.AddScoped<ChartService>(); |
| | 28 | 49 | | services.AddScoped<IKeyboardShortcutService, KeyboardShortcutService>(); |
| | 28 | 50 | | services.AddScoped<IExportService, ExportService>(); |
| | | 51 | | |
| | | 52 | | // Register formatter services for components (enables testable code with coverage tracking) |
| | 28 | 53 | | services.AddScoped<StatCardFormatter>(); |
| | 28 | 54 | | services.AddScoped<ActivityItemFormatter>(); |
| | 28 | 55 | | services.AddScoped<ActivityTimelineFormatter>(); |
| | 28 | 56 | | services.AddScoped<TimeFormatter>(); |
| | 28 | 57 | | services.AddScoped<ChartDataFormatter>(); |
| | 28 | 58 | | services.AddScoped<TimerThemeFormatter>(); |
| | 28 | 59 | | services.AddScoped<SummaryCardsFormatter>(); |
| | 28 | 60 | | services.AddScoped<ITodayStatsService, TodayStatsService>(); |
| | 28 | 61 | | services.AddScoped<IHistoryStatsService, HistoryStatsService>(); |
| | 28 | 62 | | services.AddScoped<SettingsPresenterService>(); |
| | 28 | 63 | | services.AddScoped<HistoryPagePresenterService>(); |
| | 28 | 64 | | services.AddScoped<IndexPagePresenterService>(); |
| | 28 | 65 | | services.AddScoped<IJSInteropService, JSInteropService>(); |
| | 28 | 66 | | services.AddScoped<IInfiniteScrollInterop, InfiniteScrollInterop>(); |
| | 28 | 67 | | services.AddScoped<ILocalDateTimeService, LocalDateTimeService>(); |
| | | 68 | | |
| | 28 | 69 | | _logger?.LogInformation("All services registered successfully"); |
| | 28 | 70 | | } |
| | | 71 | | } |