#What is best practice in query data of entities from other modules?
8 messages · Page 1 of 1 (latest)
The module that provides the data exports the service, the consuming modules import the module and their services inject the providing service.
But if you have 2 services that both need each other, chances are these should not be in separate modules, because they're tightly coupled
Remember that 1 entitiy != 1 module, but rather 1 "feature" which can be composed of multiple entitites
Alternatively, you can decouple the modules by using queries from "nestjs/cqrs", but again, if they both need data from each other, they likely implement different parts of the same feature
I switched from C# and worked with microservices before. So I see design of Nestjs like "modular monolith".
My purpose to keep each module like a specific domain with clear bounded context and Nestjs support it very well. In the future they can be separated as a independency service in microservices
The rest of work is keeping communication clear and easier to migrate to micro in the future.
if they both need data from each other, they likely implement different parts of the same feature I agree with this.
I separate as much as i can, but if i need to get some data in another domain, get it with a repository in my other domain don't bother me. But i avoid to import/export service, i have added another layer with customRepository, to store my queries. That's this layer that often be exported (without service buisness logic)