#What is best practice in query data of entities from other modules?

8 messages · Page 1 of 1 (latest)

stark glen
#

I understands module concept of Nestjs is used to separate domains. So what is the best practice if one module needs data from the others, is there anyway beside using exported providers?
For example I have 2 module and all of them have demands on reading data from each other.

broken root
#

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

stark glen
#

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.

rapid kernel
#

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)