Hey. I am working on an NestJS application that will be depending on Nest CQRS implementation. The app will be a complex monolith, including several modules (UsersModule, PostsModule, MessagesModule etc - just an example). I'd like to implement the onion architecture model, but I am not sure how exactly it works and how to achieve it.
Let's say we have basic command:
// UsersModule/queries
GetUserByIdQuery(id: string) => GetUserByIdQueryResult
// UsersModule/query-handlers
GetUserBydIdQueryHandler {
process(query) => { return this.db.getUserById(query.id); }
}```
---
I'd like to call mentioned query within PostsModule
const myResult = this.queryBus.dispatch(new GetUserByIdQuery(myPayload));
How this should be done?
1. Normally call queryBus for example inside PostsService like above (do i have to import usersmodule to ensure handler being accessible?
2. Wrap queryBus.dispatch into UsersModule->usersService and import UsersModule to PostsModule and do it as: `this.usersService.getUserById()` and `getUserById` dispatches query to event bus
3. Do one global infrastructure module (for example StoreModule) that has all typeorm entities, repositories and command/queries?
Like:
PostsModule imports StoreModule that has User, Post entities and their repositories
```/// some service inside PostsModule that imports StoreModule
const result = await this.storeService.executeQuery(new GetUserById(someId))