|
| 1 | +using System.Threading; |
| 2 | +using System.Threading.Tasks; |
| 3 | + |
| 4 | +namespace EasyExtensions.Mediator.Contracts |
| 5 | +{ |
| 6 | + /// <summary> |
| 7 | + /// Defines a handler for processing a request and returning a response asynchronously. |
| 8 | + /// </summary> |
| 9 | + /// <remarks>Implement this interface to define custom logic for handling specific request types in a |
| 10 | + /// request/response pattern. The handler is typically invoked by a mediator or dispatcher component. |
| 11 | + /// Implementations should be thread-safe if they are shared across multiple requests.</remarks> |
| 12 | + /// <typeparam name="TRequest">The type of the request to handle. Must implement <see cref="IRequest{TResponse}"/>.</typeparam> |
| 13 | + /// <typeparam name="TResponse">The type of the response returned by the handler.</typeparam> |
| 14 | + public interface IRequestHandler<in TRequest, TResponse> where TRequest : IRequest<TResponse> |
| 15 | + { |
| 16 | + /// <summary> |
| 17 | + /// Handles the specified request and returns a response asynchronously. |
| 18 | + /// </summary> |
| 19 | + /// <param name="request">The request message to process. Cannot be null.</param> |
| 20 | + /// <param name="cancellationToken">A cancellation token that can be used to cancel the operation.</param> |
| 21 | + /// <returns>A task that represents the asynchronous operation. The task result contains the response to the request.</returns> |
| 22 | + Task<TResponse> Handle(TRequest request, CancellationToken cancellationToken = default); |
| 23 | + } |
| 24 | + |
| 25 | + /// <summary> |
| 26 | + /// Defines a handler for processing a request of a specified type asynchronously. |
| 27 | + /// </summary> |
| 28 | + /// <remarks>Implement this interface to define custom logic for handling requests of type <typeparamref |
| 29 | + /// name="TRequest"/>. The handler is typically invoked by a mediator or dispatcher component. Implementations |
| 30 | + /// should ensure thread safety if the handler will be used concurrently.</remarks> |
| 31 | + /// <typeparam name="TRequest">The type of request to handle. Must implement the <see cref="IRequest"/> interface.</typeparam> |
| 32 | + public interface IRequestHandler<in TRequest> where TRequest : IRequest |
| 33 | + { |
| 34 | + /// <summary> |
| 35 | + /// Handles the specified request asynchronously. |
| 36 | + /// </summary> |
| 37 | + /// <param name="request">The request message to be processed. Cannot be null.</param> |
| 38 | + /// <param name="cancellationToken">A cancellation token that can be used to cancel the operation.</param> |
| 39 | + /// <returns>A task that represents the asynchronous handling operation.</returns> |
| 40 | + Task Handle(TRequest request, CancellationToken cancellationToken = default); |
| 41 | + } |
| 42 | +} |
0 commit comments