Skip to content

Instantly share code, notes, and snippets.

@wellingtonjhn
Last active September 16, 2022 23:45
Show Gist options
  • Select an option

  • Save wellingtonjhn/e7c07f8116b47247592c88cb9d831b38 to your computer and use it in GitHub Desktop.

Select an option

Save wellingtonjhn/e7c07f8116b47247592c88cb9d831b38 to your computer and use it in GitHub Desktop.
MediatR Pipeline Behavior
public class LoggingBehavior<TRequest, TResponse> : IPipelineBehavior<TRequest, TResponse>
{
public async Task<TResponse> Handle(TRequest request, CancellationToken cancellationToken, RequestHandlerDelegate<TResponse> next)
{
await Logger.InfoAsync($"Handling {typeof(TRequest).Name}");
var response = await next();
await Logger.InfoAsync($"Handled {typeof(TResponse).Name}");
return response;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment