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