Table of Contents

Interface ICommand<TResponse>

Namespace
SimpleMediator
Assembly
SimpleMediator.dll

Represents a command flowing through the mediator.

public interface ICommand<out TResponse> : IRequest<TResponse>

Type Parameters

TResponse

Type returned by the handler when the command finishes.

Examples

public sealed record CreateReservation(Guid Id, ReservationDraft Draft) : ICommand<Unit>;

public sealed class CreateReservationHandler : ICommandHandler<CreateReservation, Unit>
{
    public async Task<Unit> Handle(CreateReservation command, CancellationToken cancellationToken)
    {
        await reservations.SaveAsync(command.Id, command.Draft, cancellationToken).ConfigureAwait(false);
        await outbox.EnqueueAsync(command.Id, cancellationToken).ConfigureAwait(false);
        return Unit.Default;
    }
}

Remarks

Commands typically mutate state or trigger side effects. Keep responses explicit (for example Unit or domain DTOs) so the mediator can wrap failures in Either<MediatorError, TResponse> while honoring the Zero Exceptions policy.