CleanArch.DevKit.Mediator.Domain
0.1.0-preview.1
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
<PackageReference Include="CleanArch.DevKit.Mediator.Domain" Version="0.1.0-preview.1" />
<PackageVersion Include="CleanArch.DevKit.Mediator.Domain" Version="0.1.0-preview.1" />
<PackageReference Include="CleanArch.DevKit.Mediator.Domain" />
paket add CleanArch.DevKit.Mediator.Domain --version 0.1.0-preview.1
#r "nuget: CleanArch.DevKit.Mediator.Domain, 0.1.0-preview.1"
#:package CleanArch.DevKit.Mediator.Domain@0.1.0-preview.1
#addin nuget:?package=CleanArch.DevKit.Mediator.Domain&version=0.1.0-preview.1&prerelease
#tool nuget:?package=CleanArch.DevKit.Mediator.Domain&version=0.1.0-preview.1&prerelease
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 | 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
- CleanArch.DevKit.Domain (>= 0.1.0-preview.1)
- CleanArch.DevKit.Mediator (>= 0.1.0-preview.1)
- Microsoft.Extensions.DependencyInjection.Abstractions (>= 10.0.0)
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 |