Created
September 15, 2018 05:34
-
-
Save FuncLun/3876018345f6c6dc3b494ec0a2c6219a to your computer and use it in GitHub Desktop.
Suggested extensions for Mediator
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System.Threading; | |
using System.Threading.Tasks; | |
namespace MediatR | |
{ | |
public static class MediatorExtensions | |
{ | |
public static Task<TResponse> Send<TResponse>(this IRequest<TResponse> request, IMediator mediator, CancellationToken cancellationToken = default) | |
=> mediator.Send(request, cancellationToken); | |
public static Task Publish(this INotification notification, IMediator mediator, CancellationToken cancellationToken = default) | |
=> mediator.Publish(notification, cancellationToken); | |
public static Task<TResponse> Send<TRequest, TResponse>(this TRequest request, IRequestHandler<TRequest, TResponse> handler, CancellationToken cancellationToken = default) | |
where TRequest : IRequest<TResponse> | |
=> handler.Handle(request, cancellationToken); | |
public static Task Publish<TNotification>(this TNotification notification, INotificationHandler<TNotification> handler, CancellationToken cancellationToken = default) | |
where TNotification : INotification | |
=> handler.Handle(notification, cancellationToken); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment