Dorn.Messaging
1.0.0
See the version list below for details.
dotnet add package Dorn.Messaging --version 1.0.0
NuGet\Install-Package Dorn.Messaging -Version 1.0.0
<PackageReference Include="Dorn.Messaging" Version="1.0.0" />
<PackageVersion Include="Dorn.Messaging" Version="1.0.0" />
<PackageReference Include="Dorn.Messaging" />
paket add Dorn.Messaging --version 1.0.0
#r "nuget: Dorn.Messaging, 1.0.0"
#:package Dorn.Messaging@1.0.0
#addin nuget:?package=Dorn.Messaging&version=1.0.0
#tool nuget:?package=Dorn.Messaging&version=1.0.0
Dorn.Messaging
MIT-licensed in-process mediator. No commercial licensing, no surprises.
Implementation of Dorn.Messaging.Contracts — dispatches commands and queries to their handlers, and notifications to all registered handlers.
Registration
// One line to rule them all
builder.Services.AddMediator(typeof(CreateTodoItemCommand).Assembly);
AddMediator registers:
ISenderandIPublisheras scoped services- All
IRequestHandler<,>implementations - All
INotificationHandler<>implementations - All
IPipelineBehavior<,>implementations
Auto-discovers everything in the provided assembly via reflection.
Send a command or query
public sealed record CreateTodoItemCommand(string Title) : IRequest<Guid>;
// In your endpoint
var id = await sender.Send(new CreateTodoItemCommand("My task"), ct);
Publish domain events
// In your aggregate
public class TodoItem : AggregateRoot
{
public static TodoItem Create(string title)
{
var item = new TodoItem { Title = title };
item.AddDomainEvent(new TodoItemCreatedEvent(item.Id));
return item;
}
}
// In your DbContext — dispatches after SaveChanges
public override async Task<int> SaveChangesAsync(CancellationToken ct)
{
var events = ChangeTracker
.Entries<AggregateRoot>()
.Select(e => e.Entity)
.Where(e => e.DomainEvents.Count > 0)
.ToList();
var result = await base.SaveChangesAsync(ct);
foreach (var entity in events)
{
foreach (var domainEvent in entity.DomainEvents.ToArray())
{
await _publisher.Publish(domainEvent, ct);
entity.ClearDomainEvents();
}
}
return result;
}
Pipeline behaviors
Behaviors execute in reverse registration order — the last registered behavior is the outermost wrapper.
// Registered first → runs first (innermost)
services.AddMediator(typeof(CreateTodoItemCommand).Assembly);
services.AddTransient(typeof(IPipelineBehavior<,>), typeof(LoggingBehavior<,>));
services.AddTransient(typeof(IPipelineBehavior<,>), typeof(ValidationBehavior<,>));
The ValidationBehavior above requires FluentValidation. If your project doesn't use FluentValidation, remove or replace it.
Installation
dotnet add package Dorn.Messaging
Depends on Dorn.Messaging.Contracts and Microsoft.Extensions.DependencyInjection.Abstractions.
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net10.0 is compatible. net10.0-android was computed. net10.0-browser was computed. net10.0-ios was computed. net10.0-maccatalyst was computed. net10.0-macos was computed. net10.0-tvos was computed. net10.0-windows was computed. |
-
net10.0
- Dorn.Messaging.Contracts (>= 1.0.0)
- Microsoft.Extensions.DependencyInjection.Abstractions (>= 10.0.9)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.