public static async Task StoreAndPublishEvents(
            this IAggregate aggregate,
            IDocumentSession session,
            IEventBus eventBus,
            CancellationToken cancellationToken = default
            )
        {
            var uncommitedEvents = aggregate.DequeueUncommittedEvents();

            session.Events.Append(aggregate.Id, uncommitedEvents);
            await session.SaveChangesAsync(cancellationToken);

            await eventBus.Publish(uncommitedEvents);
        }
 public static T?PublishedEvent <T>(this IAggregate aggregate) where T : class, IEvent
 {
     return(aggregate.DequeueUncommittedEvents().LastOrDefault() as T);
 }