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

Aggregate snapshots #336

Open
wants to merge 19 commits into
base: preview
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Makes the project build
  • Loading branch information
spardadanthe authored and ethno2405 committed Mar 21, 2023
commit 0fdde96f5775807a96c131a6be25f7c195483249
2 changes: 1 addition & 1 deletion src/Elders.Cronus/EventStore/AggregateRepository.cs
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ public async Task<ReadResult<AR>> LoadAsync<AR>(AggregateRootId id) where AR : I
{
if (typeof(AR).IsSnapshotable())
{
var snapshot = await snapshotReader.ReadAsync(id);
Snapshot snapshot = await snapshotReader.ReadAsync(id);
if (snapshot is not null)
{
EventStream eventStream = await eventStore.LoadAsync(id, snapshot.Revision).ConfigureAwait(false);
Expand Down
5 changes: 3 additions & 2 deletions src/Elders.Cronus/EventStore/EventStream.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
using Elders.Cronus.Snapshots;
using System;
using System.Collections.Generic;
using System.Linq;
Expand Down Expand Up @@ -32,7 +33,7 @@ public EventStream(IList<AggregateCommit> aggregateCommits)

public IEnumerable<AggregateCommit> Commits { get { return aggregateCommits; } }

public bool TryRestoreFromSnapshot<T>(object snapshot, out T aggregateRoot)
public bool TryRestoreFromSnapshot<T>(Snapshot snapshot, out T aggregateRoot)
where T : IAmEventSourced
{
aggregateRoot = default(T);
Expand All @@ -41,7 +42,7 @@ public bool TryRestoreFromSnapshot<T>(object snapshot, out T aggregateRoot)
{
int currentRevision = aggregateCommits.Last().Revision;
aggregateRoot = (T)FastActivator.CreateInstance(typeof(T), true);
aggregateRoot.ReplayEvents(events.ToList(), currentRevision, snapshot);
aggregateRoot.ReplayEvents(events.ToList(), currentRevision, snapshot.State);
return true;
}
else
Expand Down
2 changes: 1 addition & 1 deletion src/Elders.Cronus/Snapshots/ISnapshotWriter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public interface ISnapshotReader
Task<Snapshot> ReadAsync(Urn id, int revision);
}

public record Snapshot(Urn Id, int Revision, object State);
public record Snapshot(Urn Id, int Revision, IAggregateRootState State);

public class NoOpSnapshotReader : ISnapshotReader
{
Expand Down