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,6 +1,6 @@
import { IEventBus, CalendarEvent, ResourceCalendarData } from '../types/CalendarTypes';
import { CoreEvents } from '../constants/CoreEvents';
import { calendarConfig } from '../core/CalendarConfig';
import { CalendarConfig } from '../core/CalendarConfig';
import { DateService } from '../utils/DateService';
import { ResourceData } from '../types/ManagerTypes';
@ -20,16 +20,21 @@ interface RawEventData {
* Handles data loading with improved performance and caching
*/
export class EventManager {
private events: CalendarEvent[] = [];
private rawData: ResourceCalendarData | RawEventData[] | null = null;
private eventCache = new Map<string, CalendarEvent[]>(); // Cache for period queries
private lastCacheKey: string = '';
private dateService: DateService;
private config: CalendarConfig;
constructor(private eventBus: IEventBus) {
const timezone = calendarConfig.getTimezone?.();
this.dateService = new DateService(timezone);
constructor(
private eventBus: IEventBus,
dateService: DateService,
config: CalendarConfig
) {
this.dateService = dateService;
this.config = config;
}
/**
@ -50,7 +55,7 @@ export class EventManager {
* Optimized mock data loading with better resource handling
*/
private async loadMockData(): Promise<void> {
const calendarType = calendarConfig.getCalendarMode();
const calendarType = this.config.getCalendarMode();
const jsonFile = calendarType === 'resource'
? '/src/data/mock-resource-events.json'
: '/src/data/mock-events.json';