Skip to content

Commit

Permalink
Adding convenience interface for void handlers
Browse files Browse the repository at this point in the history
  • Loading branch information
jbogard committed Apr 5, 2018
1 parent 9e9fbaa commit e000bfe
Showing 1 changed file with 13 additions and 2 deletions.
15 changes: 13 additions & 2 deletions src/MediatR/IRequestHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,17 @@ public interface IRequestHandler<in TRequest, TResponse>
Task<TResponse> Handle(TRequest request, CancellationToken cancellationToken);
}

/// <summary>
/// Defines a handler for a request with a void (<see cref="Unit" />) response.
/// You do not need to register this interface explicitly with a container as it inherits from the base <see cref="IRequestHandler{TRequest, TResponse}" /> interface.
/// </summary>
/// <typeparam name="TRequest">The type of request being handled</typeparam>
public interface IRequestHandler<in TRequest> : IRequestHandler<TRequest, Unit>
where TRequest : IRequest<Unit>
{
}


/// <summary>
/// Wrapper class for a handler that asynchronously handles a request and returns a response, ignoring the cancellation token
/// </summary>
Expand All @@ -43,7 +54,7 @@ public Task<TResponse> Handle(TRequest request, CancellationToken cancellationTo
/// Wrapper class for a handler that asynchronously handles a request and does not return a response, ignoring the cancellation token
/// </summary>
/// <typeparam name="TRequest">The type of request being handled</typeparam>
public abstract class AsyncRequestHandler<TRequest> : IRequestHandler<TRequest, Unit>
public abstract class AsyncRequestHandler<TRequest> : IRequestHandler<TRequest>
where TRequest : IRequest
{
public async Task<Unit> Handle(TRequest request, CancellationToken cancellationToken)
Expand Down Expand Up @@ -83,7 +94,7 @@ public Task<TResponse> Handle(TRequest request, CancellationToken cancellationTo
/// Wrapper class for a handler that synchronously handles a request does not return a response
/// </summary>
/// <typeparam name="TRequest">The type of request being handled</typeparam>
public abstract class RequestHandler<TRequest> : IRequestHandler<TRequest, Unit>
public abstract class RequestHandler<TRequest> : IRequestHandler<TRequest>
where TRequest : IRequest
{
public Task<Unit> Handle(TRequest request, CancellationToken cancellationToken)
Expand Down

0 comments on commit e000bfe

Please sign in to comment.