Dorn.Messaging 1.0.0

There is a newer version of this package available.
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
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="Dorn.Messaging" Version="1.0.0" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Dorn.Messaging" Version="1.0.0" />
                    
Directory.Packages.props
<PackageReference Include="Dorn.Messaging" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add Dorn.Messaging --version 1.0.0
                    
#r "nuget: Dorn.Messaging, 1.0.0"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package Dorn.Messaging@1.0.0
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=Dorn.Messaging&version=1.0.0
                    
Install as a Cake Addin
#tool nuget:?package=Dorn.Messaging&version=1.0.0
                    
Install as a Cake Tool

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:

  • ISender and IPublisher as 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 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. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
1.0.5 207 8/22/2026
1.0.4 132 8/22/2026
1.0.3 134 8/21/2026
1.0.2 143 8/17/2026
1.0.1 187 7/17/2026
1.0.0 125 7/14/2026