VSAMay 2026 · 9 min read

Building Maintainable .NET Applications with MediatR and VSA

TL;DR

MediatR is the backbone of VSA in .NET. It implements the Mediator pattern with IRequest and pipeline behaviors for cross-cutting concerns like validation, logging, and transactions.

MediatR is more than just a mediator library — it's the backbone of effective Vertical Slice Architecture in .NET. It implements the Mediator pattern with two key abstractions: IRequest for commands/queries and IRequestHandler for their handlers.

Commands, Queries, and CQRS

In VSA, each feature slice exposes its API through MediatR. Commands (which mutate state) are separate from Queries (which read state). This is CQRS — Command Query Responsibility Segregation — and it maps naturally onto VSA. A CreateOrderCommand and its handler live in Features/Orders/. The handler uses EF Core to persist the order. A GetOrderByIdQuery also lives in the same folder, optimized for reads with EF Core's no-tracking queries.

Pipeline Behaviors: Cross-Cutting Concerns

MediatR's pipeline behaviors handle cross-cutting concerns without cluttering business logic. Logging, validation, and transaction management are implemented once as behaviors and applied to all handlers automatically:

public class ValidationBehavior 
    : IPipelineBehavior
{
    public async Task Handle(TRequest req, 
        RequestHandlerDelegate next, CancellationToken ct)
    {
        var validator = _validators.GetValidator();
        if (validator != null) await validator.ValidateAsync(req, ct);
        return await next();
    }
}

This keeps your handlers clean — they focus purely on business logic while behaviors handle the plumbing.

Key Takeaways

  • MediatR provides the CQRS backbone for VSA feature slices
  • Pipeline behaviors eliminate duplicated cross-cutting code
  • Indotalent products ship with pre-configured MediatR pipelines

Explore VSA Products

Every Indotalent product uses MediatR + VSA. Complete source code — $21 each.

Explore Products