Skip to content
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

Allow event-sourced aggregates to specify how to initialize themselves from first event #455

Open
subhashb opened this issue Aug 16, 2024 · 0 comments
Labels
enhancement New feature or request

Comments

@subhashb
Copy link
Contributor

The first event generated by an event-sourced aggregate is used to initialize the aggregate instance. The remaining events are applied through methods marked apply.

        # Initialize the aggregate with the first event's payload and apply it
        aggregate = cls(**events[0].payload)
        aggregate._apply(events[0])

        # Apply the rest of the events
        for event in events[1:]:
            aggregate._apply(event)

However, this only works if the first event mirrors the aggregate's attribute structure.

We need to provide a way for aggregates to specify a special method to initialize itself from the first event.

@subhashb subhashb added the enhancement New feature or request label Aug 16, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant