Question: Core.Marten.Repository.MartenRepository.Store & Ambiente Transactions
soernt opened this issue · 0 comments
soernt commented
Hi there,
the Core.Marten.Repository.MartenRepository.Store is implemented as following:
private async Task Store(T aggregate, CancellationToken cancellationToken)
{
var events = aggregate.DequeueUncommittedEvents();
documentSession.Events.Append(
aggregate.Id,
events
);
await documentSession.SaveChangesAsync(cancellationToken);
await eventBus.Publish(events);
}
The uncommitted events are saved and published.
If a subscriber in turn also needs to save its modified aggregate and that operations fails for some reason, we ended up with some inconsistencies.
Is there an option to check if there is an ambiente transaction active and when not to explicit start one before saving and committing it after publishing the events?
I think that is somehow related to your open task Add sample outbox pattern implementation