Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/cache/cache-metrics.interceptor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<any> {
Expand Down
5 changes: 3 additions & 2 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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({
Expand Down
Loading