From 70768feef95744e2e4e52d21d266bb6e62233203 Mon Sep 17 00:00:00 2001 From: "Jeremy D. Miller" Date: Tue, 19 Nov 2024 12:44:47 -0600 Subject: [PATCH] ApplyMetadata is called for all events. Closes GH-3559 --- docs/events/projections/aggregate-projections.md | 4 ++++ src/Marten/Events/Aggregation/AggregationRuntime.cs | 6 +++++- 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/docs/events/projections/aggregate-projections.md b/docs/events/projections/aggregate-projections.md index 72e0ba96be..80b36f0ee7 100644 --- a/docs/events/projections/aggregate-projections.md +++ b/docs/events/projections/aggregate-projections.md @@ -688,6 +688,10 @@ public class TripProjection: SingleStreamProjection ## Working with Event Metadata +::: 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` 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 diff --git a/src/Marten/Events/Aggregation/AggregationRuntime.cs b/src/Marten/Events/Aggregation/AggregationRuntime.cs index 90edc8c234..6db151c542 100644 --- a/src/Marten/Events/Aggregation/AggregationRuntime.cs +++ b/src/Marten/Events/Aggregation/AggregationRuntime.cs @@ -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