#can the services of an imported module use the service of the parent module ?
21 messages · Page 1 of 1 (latest)
this is what makes nest so great to use, and makes nest such a powerful framework
nest doesn't really care who access who as long as A and B dont start to require each other you should be fine
circular dependencies are a nightmare to debug
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
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 ?
there is work around for a circular by having a middle man module, if that is what you mean?
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
can service A inject service B ?
while B imported A?
yes
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?
is this correct?
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.