CleanArch.DevKit.Mediator.Domain 0.1.0-preview.1

This is a prerelease version of CleanArch.DevKit.Mediator.Domain.
There is a newer version of this package available.
See the version list below for details.
dotnet add package CleanArch.DevKit.Mediator.Domain --version 0.1.0-preview.1
                    
NuGet\Install-Package CleanArch.DevKit.Mediator.Domain -Version 0.1.0-preview.1
                    
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="CleanArch.DevKit.Mediator.Domain" Version="0.1.0-preview.1" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="CleanArch.DevKit.Mediator.Domain" Version="0.1.0-preview.1" />
                    
Directory.Packages.props
<PackageReference Include="CleanArch.DevKit.Mediator.Domain" />
                    
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 CleanArch.DevKit.Mediator.Domain --version 0.1.0-preview.1
                    
#r "nuget: CleanArch.DevKit.Mediator.Domain, 0.1.0-preview.1"
                    
#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 CleanArch.DevKit.Mediator.Domain@0.1.0-preview.1
                    
#: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=CleanArch.DevKit.Mediator.Domain&version=0.1.0-preview.1&prerelease
                    
Install as a Cake Addin
#tool nuget:?package=CleanArch.DevKit.Mediator.Domain&version=0.1.0-preview.1&prerelease
                    
Install as a Cake Tool

CleanArch.DevKit.Mediator.Domain

Bridge between CleanArch.DevKit.Domain and CleanArch.DevKit.Mediator. Provides IDomainEventNotification (a domain event that also flows through the mediator pipeline) and a PublishDomainEventsAsync extension on IMediator that dispatches each buffered event with its concrete runtime type — so handlers registered for the specific event class are picked up.

Part of the CleanArch.DevKit toolkit.

Install

dotnet add package CleanArch.DevKit.Mediator.Domain

Pulls in CleanArch.DevKit.Domain and CleanArch.DevKit.Mediator transitively.

Quick start

// 1. Mark events that should reach the mediator pipeline.
public sealed record UserRegistered(Guid UserId, string Email) : IDomainEventNotification;

// 2. Aggregate raises the event during command processing.
public sealed class User : AggregateRoot<Guid>
{
    private User(Guid id, string email) : base(id)
        => Raise(new UserRegistered(id, email));

    public static User Register(string email) => new(Guid.NewGuid(), email);
}

// 3. Handler for the event (regular mediator notification handler).
public sealed class SendWelcomeEmail : INotificationHandler<UserRegistered>
{
    public Task Handle(UserRegistered evt, CancellationToken ct)
        => SendEmail(evt.Email, ct);
}

// 4. Unit of work drains the buffer and publishes after commit.
public sealed class CreateUserHandler(IMediator mediator, IUserRepository repo)
    : IRequestHandler<CreateUserCommand, Guid>
{
    public async Task<Guid> Handle(CreateUserCommand cmd, CancellationToken ct)
    {
        var user = User.Register(cmd.Email);
        await repo.SaveAsync(user, ct);
        await mediator.PublishDomainEventsAsync(user, ct);
        return user.Id;
    }
}

Why a typed dispatch?

IMediator.Publish<TNotification> is generic on the static type. If you wrote:

foreach (var evt in aggregate.DomainEvents)
    await mediator.Publish(evt, ct); // <-- dispatches as INotification, not UserRegistered

…the call captures TNotification = INotification at compile time and no concrete handler matches. PublishDomainEventsAsync uses a cached MakeGenericMethod per runtime type so the correct typed Publish<UserRegistered> is invoked.

What gets published?

PublishDomainEventsAsync iterates aggregate.DomainEvents and dispatches only events that also implement INotification — typically via IDomainEventNotification. Events that are IDomainEvent only are dropped from the buffer without being published. This lets you keep internal/audit-only events in the aggregate without spam-publishing them through the mediator.

The buffer is cleared in either case, so a follow-up PublishDomainEventsAsync won't re-publish the same events.

License

MIT — see LICENSE.

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.1.1 87 5/17/2026
1.1.0 78 5/17/2026
1.0.0 103 5/15/2026
0.1.0-preview.1 50 5/14/2026