Exemple #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);
            }
        }
Exemple #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);
        }
Exemple #3
0
        public static async Task PublishAsync(this IEventBus bus, IAggregateRoot aggregateRoot)
        {
            await bus.TriggerAsync(aggregateRoot.Events);

            aggregateRoot.ClearEvents();
        }