Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
public class Pipeline<TRequest, TResponse>
: ICancellableAsyncRequestHandler<TRequest, TResponse>
where TRequest : ICancellableAsyncRequest<TResponse>
{
private readonly ICancellableAsyncRequestHandler<TRequest, TResponse> _inner;
private readonly IPostRequestHandler<TRequest, TResponse>[] _postHandlers;
public Pipeline(
ICancellableAsyncRequestHandler<TRequest, TResponse> inner,
IPostRequestHandler<TRequest, TResponse>[] postHandlers
)
{
_inner = inner;
_postHandlers = postHandlers;
}
public async Task<TResponse> Handle(TRequest message, CancellationToken cancellationToken)
{
var response = await _inner.Handle(message, cancellationToken);
foreach (var postHandler in _postHandlers)
{
postHandler.Handle(message, response);
}
return response;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment