Refactors dependency injection and configuration management

Replaces global singleton configuration with dependency injection
Introduces more modular and testable approach to configuration
Removes direct references to calendarConfig in multiple components
Adds explicit configuration passing to constructors

Improves code maintainability and reduces global state dependencies
This commit is contained in:
Janus C. H. Knudsen 2025-10-30 23:47:30 +01:00
parent fb48e410ea
commit 8bbb2f05d3
30 changed files with 365 additions and 559 deletions

View file

@ -1,5 +1,5 @@
import { CoreEvents } from '../constants/CoreEvents';
import { calendarConfig } from '../core/CalendarConfig';
import { CalendarConfig } from '../core/CalendarConfig';
import { CalendarView, IEventBus } from '../types/CalendarTypes';
import { EventManager } from './EventManager';
import { GridManager } from './GridManager';
@ -8,7 +8,6 @@ import { ScrollManager } from './ScrollManager';
/**
* CalendarManager - Main coordinator for all calendar managers
* Uses singleton calendarConfig for consistent configuration access
*/
export class CalendarManager {
private eventBus: IEventBus;
@ -16,6 +15,7 @@ export class CalendarManager {
private gridManager: GridManager;
private eventRenderer: EventRenderingService;
private scrollManager: ScrollManager;
private config: CalendarConfig;
private currentView: CalendarView = 'week';
private currentDate: Date = new Date();
private isInitialized: boolean = false;
@ -25,14 +25,15 @@ export class CalendarManager {
eventManager: EventManager,
gridManager: GridManager,
eventRenderingService: EventRenderingService,
scrollManager: ScrollManager
scrollManager: ScrollManager,
config: CalendarConfig
) {
this.eventBus = eventBus;
this.eventManager = eventManager;
this.gridManager = gridManager;
this.eventRenderer = eventRenderingService;
this.scrollManager = scrollManager;
const timezone = calendarConfig.getTimezone?.();
this.config = config;
this.setupEventListeners();
}
@ -47,7 +48,7 @@ export class CalendarManager {
try {
// Debug: Check calendar type
const calendarType = calendarConfig.getCalendarMode();
const calendarType = this.config.getCalendarMode();
// Step 1: Load data
await this.eventManager.loadData();
@ -212,7 +213,7 @@ export class CalendarManager {
this.eventBus.emit('workweek:header-update', {
currentDate: this.currentDate,
currentView: this.currentView,
workweek: calendarConfig.getCurrentWorkWeek()
workweek: this.config.getCurrentWorkWeek()
});
}