Exemplo n.º 1
0
        public static async Task ApplyEvents(this IAggregateRoot root, IMicroMediator mediator)
        {
            var events = root.Events.ToList();

            root.ClearEvents();

            foreach (var e in events.AsParallel())
            {
                await mediator.PublishEventAsync(e);
            }
        }
Exemplo n.º 2
0
        public async Task <int> SaveChangesWithNoticationsAsync(IAggregateRoot aggregateRoot, CancellationToken cancellationToken = default)
        {
            if (aggregateRoot is null)
            {
                throw new ArgumentNullException(nameof(aggregateRoot));
            }

            await _mediator.DispatchDomainEventsAsync(aggregateRoot.DomainEvents);

            int result = await base.SaveChangesAsync(cancellationToken);

            aggregateRoot.ClearEvents();

            return(result);
        }
Exemplo n.º 3
0
        public static async Task PublishAsync(this IEventBus bus, IAggregateRoot aggregateRoot)
        {
            await bus.TriggerAsync(aggregateRoot.Events);

            aggregateRoot.ClearEvents();
        }