Skip to content

Commit

Permalink
Set EventSlice identity from event stream
Browse files Browse the repository at this point in the history
  • Loading branch information
erdtsieck committed Feb 6, 2025
1 parent 87aad94 commit 687ec5f
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -380,9 +380,6 @@ public async Task using_a_custom_projection_that_has_string_as_id_fetch_latest()
{
opts.Projections.Add(new ExplicitCounterThatHasStringId(), ProjectionLifecycle.Async);
opts.Events.StreamIdentity = StreamIdentity.AsString;
//opts.Schema.For<SimpleAggregateAsString>()
// .IdStrategy(new String2IdGeneration()); // This works as a workaround for this bug. But it should not be necessary
// What goes wrong? Before the aggregate gets the id assigned from the event stream, code passes a .Store() that tries to assign id by strategy
});

var streamId = $"simple|{Guid.NewGuid()}";
Expand Down
7 changes: 4 additions & 3 deletions src/Marten/Events/Aggregation/CustomProjection.cs
Original file line number Diff line number Diff line change
Expand Up @@ -375,7 +375,9 @@ async ValueTask<TDoc> ILiveAggregator<TDoc>.BuildAsync(IReadOnlyList<IEvent> eve

var documentSessionBase = session as DocumentSessionBase ?? (DocumentSessionBase)session.DocumentStore.LightweightSession();

var slice = new EventSlice<TDoc, TId>(default, session, events);
var latestEvent = events.Last();
var streamId = IdentityFromEvent(latestEvent);
var slice = new EventSlice<TDoc, TId>(streamId, session, events);
if (Lifecycle == ProjectionLifecycle.Live)
{
slice.Aggregate = await BuildAsync(session, slice.Aggregate, slice.Events()).ConfigureAwait(false);
Expand Down Expand Up @@ -420,8 +422,7 @@ public IAggregateCache<TId, TDoc> CacheFor(Tenant tenant)

public TId IdentityFromEvent(IEvent e)
{
// TODO -- come back here.
throw new NotImplementedException();
return e.StreamKey.To<TId>() ?? e.StreamId.To<TId>();
}
}

Expand Down

0 comments on commit 687ec5f

Please sign in to comment.