Request / Response
Send a request, get a typed response. Supports both return-value and void dispatch through a single IMediator interface.
Dispatch requests, publish notifications, and stream responses through strongly-typed pipelines with expression-compiled caching that eliminates per-call reflection.
// Define a request and its handler
public sealed record Ping(string Message) : IRequest<string>;
public sealed class PingHandler : IRequestHandler<Ping, string>
{
public Task<string> Handle(Ping request, CancellationToken cancellationToken)
{
return Task.FromResult($"PONG: {request.Message}");
}
}// Register and dispatch
var services = new ServiceCollection();
services.AddMediator(options =>
{
options.RegisterServicesFromAssemblyContaining<PingHandler>();
});
await using var provider = services.BuildServiceProvider();
var mediator = provider.GetRequiredService<IMediator>();
string response = await mediator.Send(new Ping("hello"));
// response == "PONG: hello"| Package | Purpose |
|---|---|
| Nerdigy.Mediator.Abstractions | Contracts only. IMediator, ISender, IPublisher, request/notification/stream interfaces, handler interfaces, pipeline and exception interfaces. |
| Nerdigy.Mediator | Runtime. Dispatchers with expression-compiled caching, pipeline executors, exception processors, notification publishers. No DI framework dependency. |
| Nerdigy.Mediator.DependencyInjection | Registration. AddMediator(...), assembly scanning, configurable service lifetimes, publisher strategy selection. |
Send, Publish, CreateStream) quickly.