Table of Contents

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

TRequest

Observed request type.

TResponse

Response 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

request TRequest

Original request.

context IRequestContext

Request context with correlation ID, user info, etc.

response Either<MediatorError, TResponse>

Response returned by the pipeline.

cancellationToken CancellationToken

Cancellation token.

Returns

Task

Remarks

Post-processors have read-only access to context. Use context for audit logging, metrics tagging, or conditional side effects.