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

Load aggregate at specific version #906

Open
Athosone opened this issue Oct 19, 2021 · 9 comments
Open

Load aggregate at specific version #906

Athosone opened this issue Oct 19, 2021 · 9 comments

Comments

@Athosone
Copy link

Hi !

In our company we are starting to use Eventflow.

We have a use case where we want to query the state of our aggregate between date range.

So far I did not see any out of the box way to do that. Did I miss something or did not understand a concept?

I think that I should use the event store and load all events for my aggregate then replay them until the desired date however I can foresee performance issue at some point.

This is where I may use snapshot,

However I did not see a way to query a snapshot from a certain date...

Do you have any advice concerning this use case?

Regards

Ayrton

@rasmus
Copy link
Member

rasmus commented Oct 20, 2021

Hi @Athosone

Just to make sure that I fully understand, you want to read the aggregate as it looked at a specific point in time? If so, then no, there isn't anything currently in the framework. But sounds like a useful thing to have.

I looked into the current available APIs and doing it yourself doesn't seem complicated. Read the events from the aggregate you are interested in via the IEventStore, do the required filtering, then create a new empty instance of your aggregate via the IAggregateFactory and simply invoke ApplyEvents with the list of filtered events on the aggregate.

@Athosone
Copy link
Author

Thanks for the quick reply

Ok then I'll experiment with this, we could contribute eventually if that's something that may interest you?

@Athosone
Copy link
Author

As for the snapshot I would need to implement a custom snapshot store which persist a new snapshot of the aggregate instead of updating the current one right ? using the timestamp / id as index

@Zev-OwitGlobal
Copy link
Contributor

Zev-OwitGlobal commented Feb 7, 2022

I have a similar need, so if it's something you want in EventFlow, I can fork and PR it for you. I would also be interested in helping contribute to the project, we are ramping up to use it here at my company. So let me know if you'd be interested in that as well.

@rasmus rasmus changed the title Noob question: Query by date Load aggregate at specific version Mar 3, 2022
@rasmus
Copy link
Member

rasmus commented Mar 3, 2022

@Athosone did you see #570

@rasmus
Copy link
Member

rasmus commented Mar 3, 2022

Something like

// Load events representing version
var domainEvents = IEventStore.LoadEventsAsync(id)
domainEvents = domainEvents.Where(e => e.AggregateSequenceNumber < selected version).ToList()

// Apply to empty aggregate
var aggregate = IAggregateFactory.CreateNewAggregateAsync(id)
aggregate.ApplyEvents(domainEvents)

@github-actions
Copy link

github-actions bot commented Apr 8, 2023

Hello there!

We hope you are doing well. We noticed that this issue has not seen any activity in the past 90 days.
We consider this issue to be stale and will be closing it within the next seven days.

If you still require assistance with this issue, please feel free to reopen it or create a new issue.

Thank you for your understanding and cooperation.

Best regards,
EventFlow

@github-actions github-actions bot added the stale label Apr 8, 2023
@rasmus rasmus added stale-exempt and removed stale labels Apr 8, 2023
@github-actions
Copy link

github-actions bot commented Jul 8, 2023

Hello there!

We hope you are doing well. We noticed that this issue has not seen any activity in the past 90 days.
We consider this issue to be stale and will be closing it within the next seven days.

If you still require assistance with this issue, please feel free to reopen it or create a new issue.

Thank you for your understanding and cooperation.

Best regards,
EventFlow

@github-actions github-actions bot added the stale label Jul 8, 2023
@rasmus
Copy link
Member

rasmus commented Jul 8, 2023

Will make it respect the stale exempt

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants