diff --git a/src/cache/cache-metrics.interceptor.ts b/src/cache/cache-metrics.interceptor.ts index 9f511b6c..b946d0ce 100644 --- a/src/cache/cache-metrics.interceptor.ts +++ b/src/cache/cache-metrics.interceptor.ts @@ -12,6 +12,7 @@ import { CacheMonitoringService } from './cache-monitoring.service'; @Injectable() export class CacheMetricsInterceptor implements NestInterceptor { + // CacheMonitoringService is expected to be a singleton provided by the CacheModule constructor(private cacheMonitoringService: CacheMonitoringService) {} intercept(context: ExecutionContext, next: CallHandler): Observable { diff --git a/src/main.ts b/src/main.ts index 02895fd2..9a6ade6a 100644 --- a/src/main.ts +++ b/src/main.ts @@ -51,8 +51,9 @@ async function bootstrap() { app.useGlobalInterceptors(new RateLimitHeadersInterceptor()); // Apply cache metrics interceptor - const cacheMonitoringService = app.get(CacheMonitoringService); - app.useGlobalInterceptors(new CacheMetricsInterceptor(cacheMonitoringService)); + // Retrieve the singleton instance from the DI container to ensure consistent dependency injection + const cacheMetricsInterceptor = app.get(CacheMetricsInterceptor); + app.useGlobalInterceptors(cacheMetricsInterceptor); app.useGlobalPipes( new ValidationPipe({