public override async Task Save(T aggregate, Guid?userId = null) { if (!aggregate.UncommitedEvents.Any()) { return; } var checkpoint = await GetNextFromCounter(nameof(Commit.CheckpointNumber)); var sequence = await GetNextFromCounter(aggregate.Id); var commit = Commit.FromAggregate(aggregate, checkpoint, sequence); var currentUser = userId == null?memberService.GetCurrentUser() : memberService.GetById(userId.Value); commit.MemberId = currentUser?.MemberId; await TryMongo(async() => { await commitsCollection.InsertOneAsync(commit); await messageBus.Publish(aggregate.UncommitedEvents); aggregate.MarkEventsAsCommitted(); logger.Debug(Messages.CommitPersisted, aggregate.Id); }); }