示例#1
0
    private async Task PublishEventsByCommitTimeAsync(CommitTime commitTime)
    {
        var targets = DomainEventTracker.GetAllEvents(commitTime);

        while (targets.TryDequeue(out var domainEvent))
        {
            if (commitTime.HasFlag(CommitTime.AfterCommit))
            {
                await _mediator.SendAsync(CreateDynamicEvent(domainEvent));
            }
            else if (commitTime.HasFlag(CommitTime.BeforeCommit))
            {
                await _mediator.SendAsync(domainEvent);
            }
        }

        // await _mediator.SendAsync(domainEvent);
        // foreach (var @event in targets)
        // {
        //     try
        //     {
        //
        //     }
        //     catch (Exception exception)
        //     {
        //         _logger.LogError(exception,
        //             @event.AggregateRootType.FullName + " has exception. " + exception.Message + " ### " +
        //             exception.StackTrace);
        //         throw new DomainException(exception.Message, exception);
        //     }
        // }
    }
示例#2
0
    public async Task <object> Handle(INextHandler next, object message)
    {
        var result = await next.Handle(message);

        var events = DomainEventTracker.GetAllEvents();

        while (events.TryDequeue(out var domainEvent))
        {
            await _mediator.SendAsync(domainEvent);
        }
        return(result);
    }