Skip to content

Instantly share code, notes, and snippets.

@FuncLun
Created September 15, 2018 05:34
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save FuncLun/3876018345f6c6dc3b494ec0a2c6219a to your computer and use it in GitHub Desktop.
Save FuncLun/3876018345f6c6dc3b494ec0a2c6219a to your computer and use it in GitHub Desktop.
Suggested extensions for Mediator
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