#can the services of an imported module use the service of the parent module ?

21 messages · Page 1 of 1 (latest)

robust field
#

If module A contains service a and module B contains service b and module B imports module A, then service b can inject service a. But can service a inject service b ?

fathom drift
robust field
#

so can service a inject service b ?

fathom drift
# robust field so can service a inject service b ?

doesn't matter who access who, as long as you dont run into the paradox of both require each other there isn't a issue
i cant say for sure about trying to get app.module imported into another module tho

robust field
#

i don't think you understand what I mean by the question. it's simply if an imported module can use the other imported modules or the parent module

#

i am aware of the circular dependency problem, but fundementally in nest can this be done ?

#

the docs clearly mention that if a module imports other modules then the services of the importing modules can inject the services of the imported modules

#

but doesn't clarify if it's also the other way

#

meaning can the services of the imported modules inject the services of the importing (parent) module or their "sibling" (imported) modules ?

#

ex:

Module A: service A

Module B: service B

B imported A, then service B can inject service A

can service A inject service B ?

#

note i said "can". so disregard circular dependency

#

you can consider that service B is not injecting service A. so can service A inject service B ?

fathom drift
#

there is work around for a circular by having a middle man module, if that is what you mean?

robust field
#

no it's not related to circular dependency

#

**Module A: service A

Module B: service B

B imported A

can service A inject service B ?**

this is the question in a nutshell

#

service B is not injecting service A so there is no circular dependency

fathom drift
robust field
#

yes

fathom drift
#

ah i think i start to understand then, but just in case

B -> A
A has now access to B
you want to call a service from B inside A?

fathom drift
ebon oyster
#

The answer is no. If service B needs service A as an injection, then service A must be exported in module A and Module B would need to import Module A and you‘d end up with a circular dependency. Parent modules should depend on their children only.