Interface IRequestPostProcessor<TRequest, TResponse>
- Namespace
- SimpleMediator
- Assembly
- SimpleMediator.dll
Executes logic after the main handler for a given request.
public interface IRequestPostProcessor<in TRequest, TResponse>
Type Parameters
TRequestObserved request type.
TResponseResponse type emitted by the handler.
Examples
public sealed class AuditLogPostProcessor<TRequest, TResponse> : IRequestPostProcessor<TRequest, TResponse>
{
private readonly IAuditLogger _auditLogger;
public Task Process(
TRequest request,
IRequestContext context,
Either<MediatorError, TResponse> response,
CancellationToken cancellationToken)
{
await _auditLogger.LogAsync(new AuditEntry
{
UserId = context.UserId,
Action = typeof(TRequest).Name,
Timestamp = context.Timestamp,
Success = response.IsRight
});
return Task.CompletedTask;
}
}
Remarks
Useful for emitting notifications, cleaning resources, or persisting additional results. Runs even when the handler returned a functional error; the implementation decides how to react.
Methods
Process(TRequest, IRequestContext, Either<MediatorError, TResponse>, CancellationToken)
Executes the post-processing logic using the request and the final response.
Task Process(TRequest request, IRequestContext context, Either<MediatorError, TResponse> response, CancellationToken cancellationToken)
Parameters
requestTRequestOriginal request.
contextIRequestContextRequest context with correlation ID, user info, etc.
responseEither<MediatorError, TResponse>Response returned by the pipeline.
cancellationTokenCancellationTokenCancellation token.
Returns
Remarks
Post-processors have read-only access to context. Use context for audit logging, metrics tagging, or conditional side effects.