Skip to content

Correct way to initialize ClsModule when multiple third party modules use CLS #175

Answered by Papooch
nishkarsh-beamery asked this question in Q&A
Discussion options

You must be logged in to vote

That's a tough call. The ClsModule isn't built such that multiple forRoot registrations in a single application are supported, as it depends on some global state (as is the case with most modules with the forRoot method).

I can straight up say, that if you use forRoot multiple times, then the Proxy Providers feature will break, because it uses a shared global array.

But, as long as nestjs-cls is a peer depency of those libraries (and/or they're de-duplicated in node_modules, meaning there's only a single place from where it is imported), then the underlying storage should be the same regardless of how many times you register it.

That said, I wouldn't recommend calling forRoot multiple tim…

Replies: 1 comment 3 replies

Comment options

You must be logged in to vote
3 replies
@nishkarsh-beamery
Comment options

@Papooch
Comment options

@Papooch
Comment options

Answer selected by nishkarsh-beamery
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