Easy to Use
NetMediate is designed to be simple and intuitive. Define your messages and handlers, register them with dependency injection, and start using the mediator pattern immediately.
Type-Safe
Built with strong typing in mind. Commands, requests, notifications, and streams are all fully typed, providing compile-time safety and excellent IDE support.
AOT Compatible
Full support for .NET Native AOT compilation with source generators. No reflection at runtime means blazing-fast performance and small deployment sizes.
Pipeline Behaviors
Implement cross-cutting concerns like logging, validation, and caching with pipeline behaviors. Wrap your handlers with reusable middleware-style interceptors.
Built-in Resilience
Optional resilience package provides retry, timeout, and circuit breaker behaviors out of the box. Make your applications more robust with minimal configuration.
Observability Ready
Native OpenTelemetry support with ActivitySource and Meter for traces and metrics. DataDog integration packages available for comprehensive observability.
Quick Example
// 1. Install the packages
dotnet add package NetMediate
dotnet add package NetMediate.SourceGeneration
// 2. Define a notification
public record UserCreated(string UserId, string Email);
// 3. Create a handler
public class UserCreatedHandler : INotificationHandler<UserCreated>
{
public Task Handle(UserCreated notification, CancellationToken ct)
{
Console.WriteLine($"User {notification.UserId} created!");
return Task.CompletedTask;
}
}
// 4. Register services
builder.Services.AddNetMediate();
// 5. Use the mediator
await mediator.Notify(new UserCreated("123", "user@example.com"));