Consider adding a @UseCls() method decorator to set up the context for a method automagically, when it is run outside of a request context.
// This is currently NOT supported
@Injectable()
export class CronController {
constructor(
private readonly cls: ClsService,
private readonly someService: SomeService
)
@Cron('45 * * * * *')
@UseCls()
handleCron() {
this.cls.set(CLS_ID, uuid())
this.someService.doTheThing();
}
}
The decorator would need to replace the method's implementation by wrapping the actual call with the cls.run() method. This would be the prefered way of entering the CLS context for invoking CLS-aware code that does not go through a controller, where a middleware or enhancer take care of setting up the context.
(relates to #18)
Consider adding a
@UseCls()
method decorator to set up the context for a method automagically, when it is run outside of a request context.The decorator would need to replace the method's implementation by wrapping the actual call with the
cls.run()
method. This would be the prefered way of entering the CLS context for invoking CLS-aware code that does not go through a controller, where a middleware or enhancer take care of setting up the context.