Skip to content
Discussion options

You must be logged in to vote

If the decorator function has the same this context as the class, you can just use the already injected ClsService, if not, you'll need to use the static ClsServiceManager to retrieve the singleton ClsService instance.

Then just wrap the middleware call and pass in the store:

return await this.clsService.runWith(context.__CLS_STORE__, () => {
  return // ... call the middleware
})

The context will be then preserved within this callback/promise chain.

(remember that cls.run/With returns whatever the callback returns)

Replies: 1 comment 5 replies

Comment options

You must be logged in to vote
5 replies
@lukaskemper
Comment options

@Papooch
Comment options

Answer selected by lukaskemper
@lukaskemper
Comment options

@Papooch
Comment options

@lukaskemper
Comment options

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants