Skip to content

Auto-Incrementing Ids assigned from repository #180

Discussion options

You must be logged in to vote

The solution I came up with (I'm working in java, so I'm only taking inspiration here) is to modify the AggregateRoot's publishEvents method to also take an aggregate Id argument. Each of the domain events are extended from a DomainEventWithAutoId base class that has an issueId method that allows a caller to mutate the domain event's Id (I could make it immutable with more work). So, the create method stores a domain event where the id is null. Then, when the repository saves the record and gets an id back, it issues it to the aggregate via aggregate.publishEvents(eventPublisher, savedAggregateId). Within that method, it iterates over all the domain events it has locally and calls event.i…

Replies: 1 comment 3 replies

Comment options

You must be logged in to vote
3 replies
@zacharyweidenbach
Comment options

@zacharyweidenbach
Comment options

@zacharyweidenbach
Comment options

Answer selected by zacharyweidenbach
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants