Nest: [Question] How to use the global modules which modules decorate with @Global()

Created on 11 Jan 2018  路  5Comments  路  Source: nestjs/nest

I note that in Module's document we've a new decorator @Global().
If I set a module as Global, How do I use it in another module without import?

Here is the version informations:

"@nestjs/common": "^4.5.6",
"@nestjs/core": "^4.5.7",
question 馃檶

Most helpful comment

As I understand It has to be imported at least once somewhere in the app.

In my case, I have global ConfigModule with exported ConfigService.
I import it at the root AppModule along with all other modules: DbModule, LoggerModule, FormsModule. Now I can just inject ConfigService in all my modules, without importing the ConfigModule everywere

All 5 comments

As I understand It has to be imported at least once somewhere in the app.

In my case, I have global ConfigModule with exported ConfigService.
I import it at the root AppModule along with all other modules: DbModule, LoggerModule, FormsModule. Now I can just inject ConfigService in all my modules, without importing the ConfigModule everywere

@myflowpl Thanks for your sharing. But if I have to import the class(not interface) that I want to use, why we use DI? why not just new className() and call its method with the instance?

@sirius1024 it's all about testing.

@sirius1024 it's nicely explained here https://angular.io/guide/dependency-injection#di-by-example

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

ZenSoftware picture ZenSoftware  路  35Comments

kamilmysliwiec picture kamilmysliwiec  路  178Comments

raydirty picture raydirty  路  37Comments

BrunnerLivio picture BrunnerLivio  路  44Comments

hypeofpipe picture hypeofpipe  路  27Comments