Notifications with clean architecture
Question:
There is a case for creating a client.
Controller -> CreateClientRequest -> CreateClientUseCase -> ClientEntity [assigned: UserEntity]
The client is assigned a responsible person assigned.
After creation, i need to notify the client about the assigned user, and the user about the incoming client.
In this case, the user has notification settings like: Email, Push, SMS.
Q: How do i implement this kind of aggregation in a clean architecture?
Answers:
You can create a dedicated notification service, fully decoupled of the client/user entities, that handles notifications in a generic way.
Whenever the assignment is completed, you use that service to fire 2 notifications, one for each entity.
Having this service decoupled will make the architecture more robust, because you can test it in a generic way, but also reuse it for other use-cases, not to mention that it follows the separation of concerns.
There is a case for creating a client.
Controller -> CreateClientRequest -> CreateClientUseCase -> ClientEntity [assigned: UserEntity]
The client is assigned a responsible person assigned.
After creation, i need to notify the client about the assigned user, and the user about the incoming client.
In this case, the user has notification settings like: Email, Push, SMS.
Q: How do i implement this kind of aggregation in a clean architecture?
You can create a dedicated notification service, fully decoupled of the client/user entities, that handles notifications in a generic way.
Whenever the assignment is completed, you use that service to fire 2 notifications, one for each entity.
Having this service decoupled will make the architecture more robust, because you can test it in a generic way, but also reuse it for other use-cases, not to mention that it follows the separation of concerns.