Skip to content

Transitio.Mediator

Hitesh Kumar edited this page Jul 15, 2026 · 3 revisions

Transitio.Mediator

A lightweight in-process mediator for .NET — CQRS-style request/response dispatch, pub/sub notifications, and pipeline behaviors.

NuGet

Table of Contents


Installation

dotnet add package Transitio.Mediator

Requirements: .NET 8.0 or later (net8.0, net10.0).


Quick Start

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 });

Request/Response

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 (Pub/Sub)

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 });

Pipeline Behaviors

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.


Dependency Injection

AddTransitioMediator scans the given assembly (or assemblies) and registers:

  • All IRequestHandler<> implementations
  • All INotificationHandler<> implementations
  • All IPipelineBehavior<,> implementations
  • The IMediator service itself
services.AddTransitioMediator(
    typeof(Program).Assembly,
    typeof(SomeOtherProject.Marker).Assembly
);

Dependencies

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.


Documentation

  • Mediator — IRequest/IRequestHandler, INotification/INotificationHandler, IPipelineBehavior, AddTransitioMediator

See the Changelog for full release history.


License

Licensed under the MIT License.


FAQ

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.

Clone this wiki locally