From d4ff107c4dbaaa87b630486cba841e323bbedba0 Mon Sep 17 00:00:00 2001 From: Enemuo-debug Date: Fri, 26 Jun 2026 17:35:57 +0100 Subject: [PATCH] fix: Ensure singleton DI for CacheMetricsInterceptor --- src/cache/cache-metrics.interceptor.ts | 1 + src/main.ts | 5 +++-- 2 files changed, 4 insertions(+), 2 deletions(-) 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 440e6e49..705457bb 100644 --- a/src/main.ts +++ b/src/main.ts @@ -49,8 +49,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({