/// <summary> /// Commits events to event store and event bus /// </summary> /// <param name="id">aggregate ID</param> /// <param name="aggregateRoot">aggregate</param> /// <param name="metadata">metadata</param> /// <returns>async task boid result</returns> public async Task CommitEventsAsync(string id, IAggregateRoot aggregateRoot, ICommandMetadata metadata) { var events = ExtractEvents(aggregateRoot, metadata).ToList(); var version = aggregateRoot.Version; events.ForEach(e => e.Version = version); await _eventSource.AppendEventsAsync(id, version, events).ConfigureAwait(false); _eventBus?.Publish(events); if (aggregateRoot.Version % SnapshotsInterval == 0) { await _snapshots.SaveAsync(new Snapshot(id, version, _serializer.Serialize(aggregateRoot.State))).ConfigureAwait(false); } }