Skip to content

Commit 06a6cf2

Browse files
committed
fix: Ensure singleton DI for CacheMetricsInterceptor
1 parent 4a7221a commit 06a6cf2

2 files changed

Lines changed: 4 additions & 2 deletions

File tree

src/cache/cache-metrics.interceptor.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import { CacheMonitoringService } from './cache-monitoring.service';
1212

1313
@Injectable()
1414
export class CacheMetricsInterceptor implements NestInterceptor {
15+
// CacheMonitoringService is expected to be a singleton provided by the CacheModule
1516
constructor(private cacheMonitoringService: CacheMonitoringService) {}
1617

1718
intercept(context: ExecutionContext, next: CallHandler): Observable<any> {

src/main.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,8 +51,9 @@ async function bootstrap() {
5151
app.useGlobalInterceptors(new RateLimitHeadersInterceptor());
5252

5353
// Apply cache metrics interceptor
54-
const cacheMonitoringService = app.get(CacheMonitoringService);
55-
app.useGlobalInterceptors(new CacheMetricsInterceptor(cacheMonitoringService));
54+
// Retrieve the singleton instance from the DI container to ensure consistent dependency injection
55+
const cacheMetricsInterceptor = app.get(CacheMetricsInterceptor);
56+
app.useGlobalInterceptors(cacheMetricsInterceptor);
5657

5758
app.useGlobalPipes(
5859
new ValidationPipe({

0 commit comments

Comments
 (0)