Repository navigation
Transitio.Mediator
A lightweight in-process mediator for .NET — CQRS-style request/response dispatch, pub/sub notifications, and pipeline behaviors.
- Installation
- Quick Start
- Request/Response
- Notifications (Pub/Sub)
- Pipeline Behaviors
- Dependency Injection
- Dependencies
- Documentation
- License
- FAQ
dotnet add package Transitio.MediatorRequirements: .NET 8.0 or later (net8.0, net10.0).
services.AddTransitioMediator(typeof(Program).Assembly);public class GetUserQuery : IRequest<UserDto>
{
public int UserId { get; set; }
}
public class GetUserHandler : IRequestHandler<GetUserQuery, UserDto>
{
public Task<UserDto> Handle(GetUserQuery request, CancellationToken cancellationToken)
{
// your logic here
}
}var user = await mediator.Send(new GetUserQuery { UserId = 42 });Requests implement IRequest<TResponse> for a typed response, or IRequest for no return value. Each request type has exactly one matching handler, implementing IRequestHandler<TRequest, TResponse> (or IRequestHandler<TRequest>).
Notifications implement INotification and can have zero or more handlers implementing INotificationHandler<TNotification>. All matching handlers run when the notification is published:
await mediator.Publish(new OrderCreatedNotification { OrderId = 101 });Behaviors implement IPipelineBehavior<TRequest, TResponse> and wrap around request handling — useful for logging, validation, caching, or timing concerns. Behaviors run in registration order, wrapping the final handler call.
AddTransitioMediator scans the given assembly (or assemblies) and registers:
- All
IRequestHandler<>implementations - All
INotificationHandler<>implementations - All
IPipelineBehavior<,>implementations - The
IMediatorservice itself
services.AddTransitioMediator(
typeof(Program).Assembly,
typeof(SomeOtherProject.Marker).Assembly
);This package brings in:
-
Microsoft.Extensions.DependencyInjection.Abstractions(>= 8.0.0)
It's fully standalone — no dependency on Transitio.Mapper or the other Transitio packages.
-
Mediator —
IRequest/IRequestHandler,INotification/INotificationHandler,IPipelineBehavior,AddTransitioMediator
See the Changelog for full release history.
Licensed under the MIT License.
Does this depend on Transitio.Mapper? No — Transitio.Mediator is fully standalone and can be used independently of the rest of the Transitio family.
Does it support streaming requests? Not currently. Being considered for a future release based on feedback.
What frameworks are supported? net8.0 and net10.0 (net9.0 is computed-compatible).
Where do I report bugs or request features? Open an issue on the GitHub repo.
Part of the Transitio family — lightweight, dependency-light .NET libraries: Transitio.Mapper · Transitio.Dependency · Transitio.Validation · Transitio.Mediator.
Home · MIT Licensed · NuGet · GitHub · @TransitioNET