Davish.SharedKernel 1.0.0

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

Davish.SharedKernel

NuGet License: MIT

Shared DDD building blocks for Davish projects: Entity, AggregateRoot, DomainEvent, and IUnitOfWork.

Install

dotnet add package Davish.SharedKernel

What's included

  • EntityBase / Entity<TId> — base types for domain entities.
  • AggregateRoot<TId> / AggregateRoot — aggregate root with domain event tracking (RaiseDomainEvent, ClearDomainEvents).
  • DomainEvent / IDomainEvent / IDomainEventHandler<TEvent> — domain event contracts, built on Davish.Sendr's notification pipeline.
  • IAggregateRootChangeTracker / AggregateRootChangeTracker — collects aggregate roots that raised events so they can be dequeued and published (e.g. before SaveChanges).
  • IUnitOfWorkBase / IUnitOfWork — commit/begin/rollback contracts for a unit of work.

Usage

Define an aggregate root and its domain events

public sealed record OrderPlaced(Guid OrderId) : DomainEvent;

public sealed class Order : AggregateRoot
{
    public static Order Place(Guid id)
    {
        var order = new Order { Id = id };
        order.RaiseDomainEvent(new OrderPlaced(id));
        return order;
    }
}

AggregateRoot is an AggregateRoot<Guid>; use AggregateRoot<TId> directly if your aggregate is identified by something other than a Guid.

Handle a domain event

public sealed class SendOrderConfirmationEmail : IDomainEventHandler<OrderPlaced>
{
    public Task Handle(OrderPlaced notification, CancellationToken cancellationToken)
    {
        // send the email
        return Task.CompletedTask;
    }
}

Track and dispatch domain events from a unit of work

public sealed class SqlUnitOfWork(IAggregateRootChangeTracker changeTracker, ISender sender) : IUnitOfWork
{
    public async Task CommitAsync(CancellationToken ct)
    {
        // persist changes here, then dispatch what was raised
        foreach (var aggregateRoot in changeTracker.Dequeue())
        {
            foreach (var domainEvent in aggregateRoot.DomainEvents)
                await sender.Publish(domainEvent, ct);

            aggregateRoot.ClearDomainEvents();
        }
    }

    public Task BeginAsync(CancellationToken ct) => Task.CompletedTask;

    public Task RollbackAsync(CancellationToken ct) => Task.CompletedTask;
}

Enqueue an aggregate root into the IAggregateRootChangeTracker whenever it's added or modified (e.g. in your repository's Add/Update methods), so CommitAsync knows which aggregates to dispatch events for.

Requirements

  • .NET 10.0+

License

MIT

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.0 107 8/21/2026