-
Notifications
You must be signed in to change notification settings - Fork 464
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Saving Aggregate with entity list #52
Comments
Hey @maranqz. I think I don't understand the context fully, but here's some thoughts:
Are you using a message queue? You might find this example useful.
I wouldn't recommend that. It means you have to load the entire aggregate every time you update it. It'll be slow and error-prone.
What are the options? It seems to me like something you'd pass to the repository's constructor, not to its methods. Hopefully that's helpful. :) Let me know. |
@m110, thank for the detailed answer.
It's just an example and I want them to be in a transaction.
I though there is a more elegant solution without creating many small methods on each operation.
Is it ok to put Pub/Sub in domain or better add in repository after saving?
I use []Option to add additional data. For example, I want to check version of a record and understand can or can't update the record. Also I use []Options to send additional non-domain data in event handlers. For analytics, I want know a User-Agent. I get this information in a controller/http handler and put in []Options. Event handler gets the User-Agent and send data about event and User-Agent in another system. |
I would say it's a trade-off. :) You can have some sort of balance, don't need to go all the way into one huge
The Pub/Sub implementation shouldn't interfere with your domain but you could have events as a domain concept. If you plan to publish events together with saving the aggregate, keep in mind transaction boundaries. Here are some examples:
This seems to me like a mix of a few different concepts. "Can update" seems like a key logic of the repository. I would choose to have it more explicit. Options seem like an optional thing you might forget to pass. On the other hand, the |
Hello Guys,
Initially, I want to say "Thank you" for your articles and the book.
Problem
Updating message is the most blur process for me.
Context
I have Chat (Aggregate) and Message (Entity, which knows nothing about Chat).
When I send a message, I want to create Chat if it doesn't exist. Then, a Message is attached to the Chat; change observing and message saving are tricky for me.
I track domain events and can handle them to update Chat and Message. *sqlx.Tx is passed in an observer to save transactionality; however, it looks complicated and hard to optimize the command with a few similar events. For example, to mark a bunch of messages as read.
Another way is to compare an old value with a new one and generate SQL for updating.
Questions
Code
The text was updated successfully, but these errors were encountered: