U
U
user_of_toster2021-07-03 13:34:27
Node.js
user_of_toster, 2021-07-03 13:34:27

How to make NestJS provider global?

At the root of app.module.ts I specified:

@Module({
  imports: [
    ConfigModule.forRoot({
      isGlobal: true,
 }),

Now I don’t need to enter ConfigService into providers anywhere like this: (it is visible globally and Nest does not throw an error that the dependency was not found)
// some-other-module
@Module({providers: [ConfigService]})


If I do this with my custom module:
// MyModule.ts
@Global()
@Module({providers: [MyService], exports: [MyService]})
export class MyModule{}

Now, if I want to use it MyServicein another module, I can not import it MyModule, but MyServiceI still need to import it into providers. Is it possible to make it so that MyServiceit was not possible to enter separately? Exactly the same asConfigService

Answer the question

In order to leave comments, you need to log in

1 answer(s)
L
lssssssssssl, 2021-07-03
@lsssssssssl

We use Global, services work fine with each other
60e074b122d1f108504143.png
. Everything frays, since the decorator is removed and the connection between them is broken
60e074b7dc74d162357020.png
Restoring the connection by adding SomeModule to SecondModule imports
60e074bf51dda851119599.png
It's not entirely clear what exactly you don't like.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question