Athenex.Whimclean.Infrastructure 2.0.0

Prefix Reserved
dotnet add package Athenex.Whimclean.Infrastructure --version 2.0.0
                    
NuGet\Install-Package Athenex.Whimclean.Infrastructure -Version 2.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="Athenex.Whimclean.Infrastructure" Version="2.0.0" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Athenex.Whimclean.Infrastructure" Version="2.0.0" />
                    
Directory.Packages.props
<PackageReference Include="Athenex.Whimclean.Infrastructure" />
                    
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 Athenex.Whimclean.Infrastructure --version 2.0.0
                    
#r "nuget: Athenex.Whimclean.Infrastructure, 2.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 Athenex.Whimclean.Infrastructure@2.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=Athenex.Whimclean.Infrastructure&version=2.0.0
                    
Install as a Cake Addin
#tool nuget:?package=Athenex.Whimclean.Infrastructure&version=2.0.0
                    
Install as a Cake Tool

Athenex.Whimclean.Infrastructure

ภาษาไทย

Provider-neutral infrastructure building blocks used by the Whimclean EF Core integration: audit actor resolution, the in-process domain-event pipeline, and deterministic seed identifiers.

Install

dotnet add package Athenex.Whimclean.Infrastructure

Audit actor resolution

IAuditActorResolver<TUserId, TActor> (in Athenex.Whimclean.Infrastructure.Auditing) converts the authenticated user identifier into the representation stored by audit columns.

For a Guid user ID stored in nullable Guid? audit properties:

using Athenex.Whimclean.Infrastructure;

services.AddNullableAuditActorResolver<Guid>();

When the types are identical and non-nullable:

services.AddIdentityAuditActorResolver<Guid>();

Both helpers register a singleton with TryAdd semantics (NullableAuditActorResolver<TUserId> requires a value type; IdentityAuditActorResolver<TActor> returns the id unchanged). Implement the interface yourself when audit actors require mapping to a name, service account, or value object:

using Athenex.Whimclean.Infrastructure.Auditing;

services.AddSingleton<
    IAuditActorResolver<Guid, ActorStamp>,
    ActorStampResolver>();

Domain-event pipeline

The package ships an in-process pipeline in Athenex.Whimclean.Infrastructure.DomainEvents: IDomainEventDispatcher delivers each committed event to every IDomainEventHandler<TEvent> registered for its runtime type. The unit of work invokes the dispatcher after a successful commit, so a handler failure never rolls the persisted changes back.

using Athenex.Whimclean.Infrastructure;

services.AddDomainEventDispatcher();
services.AddDomainEventHandler<OrderPlaced, SendConfirmationEmail>();
services.AddDomainEventHandler<OrderPlaced, ReserveStock>();

AddDomainEventDispatcher registers ServiceProviderDomainEventDispatcher as a scoped service with TryAdd semantics; AddDomainEventHandler registers the handler as scoped with TryAddEnumerable, so several handlers may react to one event while duplicate registrations collapse to one.

using Athenex.Whimclean.Application.Email;
using Athenex.Whimclean.Infrastructure.DomainEvents;

public sealed class SendConfirmationEmail(IEmailSender emailSender)
    : IDomainEventHandler<OrderPlaced>
{
    public Task HandleAsync(
        OrderPlaced domainEvent,
        CancellationToken cancellationToken = default) =>
        emailSender.SendAsync(
            new EmailMessage(
                "member@example.com",
                "Order confirmed",
                $"Order {domainEvent.OrderId} has been placed."),
            cancellationToken);
}

Dispatch failures

When a handler throws after the commit succeeded, the save surfaces a DomainEventDispatchException. The save must not be retried — the data is already persisted; the events that never reached their handlers are on UndeliveredEvents (the failing event first, then any never attempted), ready to be handled or replayed. The EF Core unit of work clears each aggregate's events before dispatching, so events raised by a handler during dispatch survive for the next commit, and it dispatches with CancellationToken.None so a cancelled request cannot abort delivery for changes that are already persisted.

Bridging to a mediator

The default dispatcher is replaceable: register your own IDomainEventDispatcher (before or instead of AddDomainEventDispatcher — TryAdd leaves it in place) to bridge into a mediator or message dispatcher. The example below targets a MediatR-style IMediator whose Publish accepts any object:

using Athenex.Whimclean.Domain.Events;
using Athenex.Whimclean.Infrastructure.DomainEvents;

public sealed class MediatorDomainEventDispatcher(IMediator mediator)
    : IDomainEventDispatcher
{
    public Task DispatchAsync(
        IDomainEvent domainEvent,
        CancellationToken cancellationToken = default) =>
        mediator.Publish(domainEvent, cancellationToken);
}
services.AddScoped<IDomainEventDispatcher, MediatorDomainEventDispatcher>();

For the source-generated martinothamar/Mediator, the Athenex.Whimclean.Mediator package already ships this bridge as AddMediatorDomainEventDispatcher(); see its README.

This package deliberately does not select MediatR, EF Core, a database provider, Identity, or multitenancy.

Deterministic seed identifiers

DeterministicGuid.Create(parentId, key) (in Athenex.Whimclean.Infrastructure.Seeding) derives a stable identifier from a parent id and a key by hashing them with SHA-256, so seeded rows such as system roles get the same id in every environment and seeders stay idempotent. The Create(key) overload uses Guid.Empty as the parent for top-level seed rows:

using Athenex.Whimclean.Infrastructure.Seeding;

var ownerRoleId = DeterministicGuid.Create(tenantId, "owner");

Repository and full architecture guide: https://github.com/athene-x/Whimclean

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 (2)

Showing the top 2 NuGet packages that depend on Athenex.Whimclean.Infrastructure:

Package Downloads
Athenex.Whimclean.Infrastructure.EntityFrameworkCore

Provider-neutral EF Core infrastructure for Whimclean applications, including required current-user writes, shadow-property audit stamps and soft deletion (HasAuditStamps, HasSoftDelete), concurrency handling, unit-of-work registration, list query helpers, and domain-event dispatch.

Athenex.Whimclean.Mediator

Optional Mediator (martinothamar/Mediator) integration: a command unit-of-work pipeline behavior and domain-event delivery as mediator notifications.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
2.0.0 160 11/17/2026

2.0.0: first nuget.org release. Provider-neutral audit actor resolution, the in-process domain-event pipeline with asynchronous dispatch, and DeterministicGuid for stable seed identifiers.