Skip to content

Commit 17a9323

Browse files
committed
docs: address some feedback from the PR
1 parent aa56fc2 commit 17a9323

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed

content/fundamentals/dynamic-modules.md

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -265,11 +265,12 @@ export const CONFIG_OPTIONS = 'CONFIG_OPTIONS';
265265

266266
You may have seen the use for methods like `forRoot`, `register`, and `forFeature` around some of the `@nestjs/` packages and may be wondering what the difference for all of these methods are. There is no hard rule about this, but the `@nestjs/` packages try to follow these guidelines:
267267

268-
When creating a module with `register` you are expecting to configuring a dynamic module for this module only with a specific configuration. For example, with Nest's `@nestjs/axios`: `HttpModule.register({{ '{' }} baseUrl: 'someUrl' {{ '}' }})`. If, in another module you use `HttpModule.register({{ '{' }} baseUrl: 'somewhere else' {{ '}' }})`, it will have the different configuration. You can do this for as many modules as you want.
268+
When creating a module with `register`, you are expecting to configure a dynamic module with a specific configuration for use only by the calling module . For example, with Nest's `@nestjs/axios`: `HttpModule.register({{ '{' }} baseUrl: 'someUrl' {{ '}' }})`. If, in another module you use `HttpModule.register({{ '{' }} baseUrl: 'somewhere else' {{ '}' }})`, it will have the different configuration. You can do this for as many modules as you want.
269269

270-
When creating a module with `forRoot`, you are expecting to configure a dynamic module once and re-using that configuration in multiple places (though possibly unknowingly as it's abstracted away). This is why you have one `GraphQLModule.forRoot()`, one `TypeOrmModule.forRoot()`, etc.
270+
When creating a module with `forRoot`, you are expecting to configure a dynamic module once and reuse that configuration in multiple places (though possibly unknowingly as it's abstracted away). This is why you have one `GraphQLModule.forRoot()`, one `TypeOrmModule.forRoot()`, etc.
271+
272+
When creating a module with `forFeature`, you are expecting to use the configuration of a dynamic module's `forRoot` but need to modify some configuration specific to the calling module's needs (i.e. which repository this module should have access to, or the context that a logger should use.)
271273

272-
When creating a module with `forFeature` you are expecting to use the configuration of a dynamic module's `forRoot` but need module specific configuration like which repository this module should have access to, or the context that a logger should use.
273274

274275
All of these, usually, have their `async` counterparts as well, `registerAsync`, `forRootAsync`, and `forFeatureAsync`, that mean the same thing, but use Nest's Dependency Injection for the configuration as well.
275276

0 commit comments

Comments
 (0)