Correct way to initialize ClsModule when multiple third party modules use CLS #175
-
|
I am working on a NestJS application that uses multiple custom node modules that use CLS. For example, a library for managing auth and another for traceability. Both of the libraries export NestJS modules that import and use What would be the effect when |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 3 replies
-
|
That's a tough call. The 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 That said, I wouldn't recommend calling forRoot multiple times, the library wasn't built for it. |
Beta Was this translation helpful? Give feedback.
That's a tough call. The
ClsModuleisn't built such that multipleforRootregistrations in a single application are supported, as it depends on some global state (as is the case with most modules with theforRootmethod).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-clsis 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…