Reputation: 3
I have 2 modules. One (payment) is responsible for payments. The second (auth) should send a verification request to a third-party server. I wanted to make the (auth) module global so that I can freely inject its methods and not use "export" and "import" for my "providers". But for some reason this doesn't work, the @Global decorator seems to be simply ignored.
What am I doing wrong?
Example on codebox: https://codesandbox.io/s/nest-forked-gsy160?file=/src/auth/auth.module.ts
Upvotes: 0
Views: 1042
Reputation: 70151
You still need to use exports
to allow access to the module's public providers. Once you add in exports
this will work fine.
You can think of a module like a container with its private API (non-exported providers), public API (exported providers), entrypoints (controllers, resolvers, gateways) and configurations (imports). You need to export the providers to make them public and available. The @Global()
will just mean you don't need to add the AuthModule
to other module's imports
(besides your root module)
Upvotes: 1