Getting started
Mediant targets .NET 8, 9 and 10.
1. Install
dotnet add package MediantOptional packages, added as you need them:
| Package | What it adds |
|---|---|
Mediant.Behaviors | The 11 built-in pipeline behaviors |
Mediant.FluentValidation | FluentValidation integration (auto-discovery, multi-validator) |
Mediant.AspNetCore | [HttpEndpoint] mapping, Result-to-HTTP, OpenAPI |
Mediant.SourceGenerator | Compile-time, AOT-safe registration & dispatch |
Mediant.EntityFrameworkCore | Durable EF Core stores for the outbox and audit |
Mediant.Analyzers | Roslyn analyzers that catch attribute misuse at compile time |
Mediant.Contracts | Shared contracts for multi-project solutions |
2. Register
builder.Services.AddMediant(cfg => cfg.RegisterServicesFromAssembly(typeof(Program).Assembly));3. Define a command
Commands change state; queries read it. Mediant makes that explicit.
public record CreateOrderCommand(string UserId, List<OrderItem> Items) : ICommand<Result<Guid>>;4. Handle it
Handlers return ValueTask<T> and carry failures in a Result<T> — no exceptions for control flow.
public class CreateOrderHandler : ICommandHandler<CreateOrderCommand, Result<Guid>>{ public ValueTask<Result<Guid>> Handle(CreateOrderCommand request, CancellationToken ct) { var orderId = Guid.NewGuid(); // ... create the order return new ValueTask<Result<Guid>>(Result<Guid>.Success(orderId)); }}5. Send it
var result = await mediator.Send(new CreateOrderCommand("user-1", items));
result.Match( id => Console.WriteLine($"Order created: {id}"), error => Console.WriteLine($"Failed: {error.Description}"));Configuration
builder.Services.AddMediant(cfg =>{ cfg.RegisterServicesFromAssembly(typeof(Program).Assembly); cfg.NotificationPublishStrategy = NotificationPublishStrategy.Parallel; cfg.EnablePolymorphicNotifications = true; cfg.ValidateOnStartup = true; // fail fast on a missing handler
cfg.AddOpenBehavior(typeof(MyLoggingBehavior<,>)); // wraps every request});
builder.Services.AddMediantValidation(typeof(Program).Assembly);builder.Services.AddMediantAllBehaviors();Namespaces
using Mediant.Abstractions; // ICommand, IQuery, handlers, behaviorsusing Mediant.Results; // Result<T>, Error, ErrorTypeNext steps
- Commands & queries — the CQRS surface.
- The Result pattern — errors without exceptions.
- Pipeline behaviors — the 11 built-ins.
- Coming from MediatR? Migrate in a few steps.