AnyMediator runs your requests, notifications and pipeline behaviors in-process. Apache-2.0, with no license key and no revenue limit.
dotnet add package AnyMediatorPick a file from a MediatR project, or paste your own. The changes AnyMediator needs are applied as you type, in your browser.
−using MediatR;
+using AnyMediator;
using MyApp.Users;
var builder = WebApplication.CreateBuilder(args);
−builder.Services.AddMediatR(cfg =>
+builder.Services.AddAnyMediator(cfg =>
{
− cfg.LicenseKey = builder.Configuration["MediatR:Key"];
cfg.RegisterServicesFromAssemblyContaining<GetUserHandler>();
cfg.AddOpenBehavior(typeof(LoggingBehavior<,>));
});
var app = builder.Build();
app.MapGet("/users/{id}", (int id, ISender sender) =>
sender.Send(new GetUser(id)));
app.Run();
Behaviors, handlers, Send(object) and Publish work as in MediatR.
Read the full migration guide Then swap the package: dotnet remove package MediatR and dotnet add package AnyMediator.
First, install the package.
$ dotnet add package AnyMediatorinfo : Adding PackageReference for package 'AnyMediator' into project 'MyApp.csproj'.
info : PackageReference for package 'AnyMediator' version '2.0.0' added to file 'MyApp.csproj'.Then, register it with your services.
builder.Services.AddAnyMediator(cfg =>
{
cfg.RegisterServicesFromAssemblyContaining<Program>();
cfg.AddOpenBehavior(typeof(LoggingBehavior<,>));
cfg.AddOpenBehavior(typeof(ValidationBehavior<,>));
});
ISender, IPublisher, IMediator | the mediator itself |
IRequestHandler<GetUser, User> | GetUserHandler, found by scanning |
IPipelineBehavior<,> | LoggingBehavior, then ValidationBehavior |
Finally, send a request.
var user = await sender.Send(new GetUser(42));What runs, in registration order
LoggingBehavior before next()ValidationBehavior before next()GetUserHandler.Handle returns the user with Id 42ValidationBehavior after next()LoggingBehavior after next(), then the response goes back to the callerIRequest<TResponse>IRequestHandler<TRequest, TResponse>IStreamRequestHandler<TRequest, T>ISender.Send / CreateStreamINotificationINotificationHandler<TNotification>IPublisher.PublishIPipelineBehavior<TRequest, TResponse>IStreamPipelineBehavior<TRequest, T>RequestHandlerDelegate<TResponse>IRequestPreProcessor<TRequest>IRequestPostProcessor<TRequest, TResponse>IRequestExceptionHandler<TRequest, TResponse, TException>IRequestExceptionAction<TRequest, TException>RequestExceptionHandlerState<TResponse>INotificationSinkINotificationPublisherTaskWhenAllPublisherRuns on.NET 8.NET 10ASP.NET CoreWorker servicesAzure FunctionsConsole apps
Install it, register it, and keep the handlers you already wrote.