I don't know how to look for this so I apologize if this is already answered.
I'm wondering how to decide what is best in terms of SRP and explicit business rules.
I feel that writing business logic dependent on events is somewhat weird
For example, I have a Command Handler. The resulting system status from calling this command handler is supposed to end with a user linked in a table with an external provider ID, and generate an active subscription in the system.
Example:
google_users (google_id, user_id) -> new record
subscriptions (user_id) -> new record
Then the question is, what is the correct approach?
- Handler calls repository to associate Google user
- Repository has business rules, when this happens, we:
- Associate the user in google_users
- Create a subscription
This does too many things?
Versus
- Handler calls repository to associate Google User
- Repository associates google_users record
- Handler fires event (Google User Associated)
- Event then has listeners, one of them is Create Subscription
- Event executes and creates the subscription
This has somewhat "indirect" business rules through events?
Like both have pros/cons