Beispiel #1
0
    private async Task SendNotification(PrincipalCommandBase <TResponse> request, TResponse response, CancellationToken cancellationToken)
    {
        var operation = request switch
        {
            EntityCreateCommand <TEntityModel, TResponse> _ => EntityChangeOperation.Created,
            EntityDeleteCommand <TKey, TResponse> _ => EntityChangeOperation.Deleted,
            _ => EntityChangeOperation.Updated
        };

        var notification = new EntityChangeNotification <TResponse>(response, operation);
        await _mediator.Publish(notification, cancellationToken);
    }
}
Beispiel #2
0
    protected override async Task <TResponse> Process(PrincipalCommandBase <TResponse> request, CancellationToken cancellationToken, RequestHandlerDelegate <TResponse> next)
    {
        if (request is null)
        {
            throw new ArgumentNullException(nameof(request));
        }

        if (next is null)
        {
            throw new ArgumentNullException(nameof(next));
        }

        var response = await next().ConfigureAwait(false);

        await SendNotification(request, response, cancellationToken);

        return(response);
    }