Skip to content

Commit

Permalink
ApplyMetadata is called for all events. Closes GH-3559
Browse files Browse the repository at this point in the history
  • Loading branch information
jeremydmiller committed Nov 19, 2024
1 parent 8bf4d89 commit 70768fe
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
4 changes: 4 additions & 0 deletions docs/events/projections/aggregate-projections.md
Original file line number Diff line number Diff line change
Expand Up @@ -688,6 +688,10 @@ public class TripProjection: SingleStreamProjection<Trip>

## Working with Event Metadata <Badge type="tip" text="7.12" />

::: info
As of Marten 7.33, this mechanism executes for every single event in the current event slice in order.
:::

At any point in an `Apply()` or `Create()` or `ShouldDelete()` method, you can take in either the generic `IEvent` wrapper
or the specific `IEvent<T>` wrapper type for the specific event. _Sometimes_ though, you may want to automatically take your
aggregated document with metadata from the very last event the projection is encountering at one time. _If_ you are using
Expand Down
6 changes: 5 additions & 1 deletion src/Marten/Events/Aggregation/AggregationRuntime.cs
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,11 @@ public async ValueTask ApplyChangesAsync(DocumentSessionBase session,
{
Versioning.TrySetVersion(aggregate, lastEvent);

Projection.ApplyMetadata(aggregate, lastEvent);
foreach (var @event in slice.Events())
{
Projection.ApplyMetadata(aggregate, @event);
}

}

// Delete the aggregate *if* it existed prior to these events
Expand Down

0 comments on commit 70768fe

Please sign in to comment.