You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
**⚠️ IMPORTANT**: When using `@WithContext`, it **must be placed closer to the function definition** than other decorators to ensure proper context initialization.
495
+
496
+
```typescript
497
+
// ✅ Correct - @WithContext closer to function
498
+
@MessagePattern('user.created')
499
+
@WithContext(() => ({ correlationId: uuid() }))
500
+
asynchandleUserCreated(data: CreateUserDto) {
501
+
this.logger.log('Processing user creation');
502
+
}
503
+
504
+
// ❌ Incorrect - @WithContext too far from function
505
+
@WithContext(() => ({ correlationId: uuid() }))
506
+
@MessagePattern('user.created')
507
+
asynchandleUserCreated(data: CreateUserDto) {
508
+
this.logger.log('Processing user creation'); // Context may not be available
509
+
}
510
+
```
511
+
512
+
This applies to all NestJS decorators including `@MessagePattern`, `@EventPattern`, `@Cron`, etc.
0 commit comments