TimeWarp.Mediator contracts and analyzers: IRequest, ICommand, IQuery, INotification, their handler and pipeline-behavior interfaces, ISender/IPublisher/IMediator, the membership attributes the source generator reads, and TWM001–TWM004. Reference it from message libraries without depending on a dispatcher.

Latest stable 14.0.0
Latest prerelease 15.0.0-beta.5
Downloads 18,903
Last published 2026-11-05
Target frameworks net10.0, net11.0

Install

dotnet add package TimeWarp.Mediator
dotnet add package TimeWarp.Mediator --prerelease

NuGet · Source · Part of the timewarp-mediator family


TimeWarp.Mediator

Message contracts and the TWM001–TWM004 and TWM012 analyzer for TimeWarp Mediator 15.0: requests, commands, queries, notifications, and pipeline types.

Install

dotnet add package TimeWarp.Mediator --version 15.0.0-beta.5

Without --version, that command resolves 14.0.0. Through 14.0.0 this package id was the reflection runtime (AddMediator). The 14.0.0 contracts were TimeWarp.Mediator.Contracts, and the analyzers were TimeWarp.Mediator.Analyzers. 15.0 reuses this id for the contracts and the analyzer. A host also references TimeWarp.Mediator.Generators at the same version. This package ships the TWM001–TWM004 and TWM012 analyzer, and GeneratedHandlerAttribute so a request can name a handler another generator emits. There is no separate analyzers package.

Example

using Microsoft.Extensions.DependencyInjection;
using TimeWarp.Mediator;
using TimeWarp.Mediator.Generated;

ServiceCollection services = new();
services.AddGeneratedMediator();
using ServiceProvider provider = services.BuildServiceProvider();
using IServiceScope scope = provider.CreateScope();
string reply = await scope.ServiceProvider.GetRequiredService<ISender>().Send(new Ping());

public sealed class Ping : IRequest<string> { }

public sealed class PingHandler : IRequestHandler<Ping, string>
{
  public ValueTask<string> Handle(Ping request, CancellationToken cancellationToken) =>
    ValueTask.FromResult("Pong");
}

AddGeneratedMediator() is emitted into the host project by TimeWarp.Mediator.Generators, in the generated namespace (TimeWarp.Mediator.Generated unless the host sets TimeWarpMediatorNamespace). Call it from the host. Reference only this package from a project that declares messages and does not dispatch them. That project still gets TWM001–TWM004, and it opts in with [assembly: MediatorAssembly].

Migration

15.0 is a breaking release. Handlers return ValueTask. The host calls AddGeneratedMediator() and supplies IServiceProvider. Registered pipeline behaviors are woven.

Steps: Migration to 15.0.

Documentation

License

Licensed as Unlicense AND Apache-2.0. The Apache-2.0 terms cover code derived from MediatR by Jimmy Bogard. The notice and unlicense files ship in this package.