3030using EventFlow . EventStores ;
3131using EventFlow . Extensions ;
3232using EventFlow . Snapshots ;
33+ using EventFlow . Snapshots . Strategies ;
3334
3435namespace EventFlow . Aggregates
3536{
@@ -39,10 +40,14 @@ public abstract class SnapshotAggregateRoot<TAggregate, TIdentity, TSnapshot> :
3940 where TIdentity : IIdentity
4041 where TSnapshot : ISnapshot
4142 {
43+ protected ISnapshotStrategy SnapshotStrategy { get ; }
44+
4245 protected SnapshotAggregateRoot (
43- TIdentity id )
46+ TIdentity id ,
47+ ISnapshotStrategy snapshotStrategy )
4448 : base ( id )
4549 {
50+ SnapshotStrategy = snapshotStrategy ;
4651 }
4752
4853 public int ? SnapshotVersion { get ; private set ; }
@@ -73,13 +78,22 @@ public override async Task LoadAsync(
7378 ApplyEvents ( domainEvents ) ;
7479 }
7580
76- public override Task < IReadOnlyCollection < IDomainEvent > > CommitAsync (
81+ public override async Task < IReadOnlyCollection < IDomainEvent > > CommitAsync (
7782 IEventStore eventStore ,
7883 ISnapshotStore snapshotStore ,
7984 ISourceId sourceId ,
8085 CancellationToken cancellationToken )
8186 {
82- return base . CommitAsync ( eventStore , snapshotStore , sourceId , cancellationToken ) ;
87+ var domainEvents = await CommitAsync ( eventStore , snapshotStore , sourceId , cancellationToken ) . ConfigureAwait ( false ) ;
88+
89+ if ( ! await SnapshotStrategy . ShouldCreateSnapshotAsync ( this , cancellationToken ) . ConfigureAwait ( false ) )
90+ {
91+ return domainEvents ;
92+ }
93+
94+
95+
96+ return domainEvents ;
8397 }
8498
8599 public async Task < SnapshotContainer > CreateSnapshotContainerAsync ( CancellationToken cancellationToken )
0 commit comments