#How to include dynamic module more that once
13 messages · Page 1 of 1 (latest)
Do you want to configure the dynamic module once and re-use it?
yes
I guess the forRoot should be called before other modules try to use it though
I'd make a wrapper module for it that does
@Module({
imports: [DynamicModule.forRoot(options)],
exports: [DynamicModule],
})
export class DyanicWrapperMoudle {}
And then add DynamicWrapperModule where you need the confgured dynamic module
I see
I would think this would be a common pattern? there is a convention with naming the static methods. You don't think the second static method is a good idea?
You could use a second static method. @golevelup/nestjs-module actually included one for situations like this. It used an observable race between a timeout and retrieving the existing configuration, so there would never really be a timewhen the timeout would hit. I can find that setup if you want
Id be interested to peek at it. basically i am struggling with naming the wrapper module because they are both the same exact thing😂 ...so previous conventions helpful to review
This is the exact code for it: https://github.com/golevelup/nestjs/blob/master/packages/modules/src/dynamicModules.ts#L155
I'll try to find my old repo that was used to come up with this solution
Here we are: https://github.com/jmcdo29/dynamic-module-test
Cool thanks a lot. I like the ExternallyConfigured so i might do the wrapper module and just Module and ExternallyConfiguredModule when importing. That solves my naming dilema
jsut for late onlookers. i ended up doing the dynamic-module-test because I like being able to run the forRootcall at my AppModule level, instead of nested behind a wrapper module! This is nice trick and should be in the docs this way i think