Exemplo n.º 1
0
        public async Task SaveAsync(TA aggregateRoot, CancellationToken cancellationToken = default)
        {
            var events = aggregateRoot.FlushUncommittedEvents();

            if (!events.Any())
            {
                return;
            }

            await _eventStore.AppendAsync(events, cancellationToken);

            try
            {
                foreach (var @event in events)
                {
                    await _eventPublisher.PublishAsync(@event, cancellationToken);
                }
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
                throw;
            }
        }