Kongroo.BuildingBlocks.Application
0.2.0
dotnet add package Kongroo.BuildingBlocks.Application --version 0.2.0
NuGet\Install-Package Kongroo.BuildingBlocks.Application -Version 0.2.0
<PackageReference Include="Kongroo.BuildingBlocks.Application" Version="0.2.0" />
<PackageVersion Include="Kongroo.BuildingBlocks.Application" Version="0.2.0" />
<PackageReference Include="Kongroo.BuildingBlocks.Application" />
paket add Kongroo.BuildingBlocks.Application --version 0.2.0
#r "nuget: Kongroo.BuildingBlocks.Application, 0.2.0"
#:package Kongroo.BuildingBlocks.Application@0.2.0
#addin nuget:?package=Kongroo.BuildingBlocks.Application&version=0.2.0
#tool nuget:?package=Kongroo.BuildingBlocks.Application&version=0.2.0
🦘 Kongroo.BuildingBlocks.Application
Application-layer building blocks for the application layer of my .NET microservices — an in-process
domain-event dispatcher, CQRS command/query contracts, a unit-of-work seam, an integration-event base,
and startup initializers. Builds on Kongroo.BuildingBlocks.Domain plus one DI abstraction, and stays
AOT-compatible.
Installation
dotnet add package Kongroo.BuildingBlocks.Application
Building blocks
| Type | Purpose |
|---|---|
IDomainEventHandler / DomainEventHandler<TDomainEvent> |
Strongly-typed domain-event handler and its base |
IDomainEventDispatcher |
In-process dispatcher: snapshots an aggregate's events, invokes handlers, clears |
ICommand / ICommand<TResult> |
Markers for state-changing commands |
ICommandHandler<TCommand> / ICommandHandler<TCommand, TResult> |
Command handler contracts |
IQuery<TResult> / IQueryHandler<TQuery, TResult> |
Read-query contracts |
IUnitOfWork |
Commit seam over the current transaction (e.g. a DbContext) |
IntegrationEvent |
Base record for cross-service events (UUIDv7 IntegrationEventId + UTC OccurredAt) |
IApplicationInitializer |
Ordered startup task, gated by IsEnabledAsync |
AddDomainEventHandler<THandler>() |
AOT-safe DI registration; also wires the in-process dispatcher |
Usage
using Kongroo.BuildingBlocks.Application;
using Microsoft.Extensions.DependencyInjection;
// A domain-event handler — derive from the typed base:
public sealed class OrderPlacedHandler : DomainEventHandler<OrderPlaced>
{
protected override Task HandleAsync(OrderPlaced domainEvent, CancellationToken cancellationToken)
{
// react to the event…
return Task.CompletedTask;
}
}
// A command and its handler — plain contracts, no mediator:
public sealed record ConfirmOrder(OrderId OrderId) : ICommand;
public sealed class ConfirmOrderHandler(IUnitOfWork unitOfWork) : ICommandHandler<ConfirmOrder>
{
public async Task HandleAsync(ConfirmOrder command, CancellationToken cancellationToken)
{
// load the aggregate, mutate it, then commit via EF Core…
await unitOfWork.CommitAsync(cancellationToken);
}
}
// Registration — one call per handler; the in-process dispatcher is wired automatically:
services.AddDomainEventHandler<OrderPlacedHandler>();
services.AddScoped<ICommandHandler<ConfirmOrder>, ConfirmOrderHandler>();
After persisting an aggregate, an infrastructure component (e.g. an EF Core SaveChanges interceptor)
calls IDomainEventDispatcher.DispatchAsync(aggregates, …), which invokes each matching
IDomainEventHandler and then clears the aggregates. CQRS handlers carry no dispatcher — inject the
handler interface directly where you need it.
Design notes
- No mediator: commands and queries are plain handler contracts you inject and call directly — no
ISender, no pipeline behaviors. - Explicit registration: handlers are registered one by one (
AddDomainEventHandler<T>), so there is no assembly scanning or reflection and the package stays AOT/trim-safe. The first call also registers the in-processIDomainEventDispatcher. - Dispatch is in-process and sequential: an aggregate's events are snapshotted before any handler runs, handlers fail fast, and sources are cleared only after a clean pass.
- Errors are exceptions (
Kongroo.BuildingBlocks.Domain'sDomainException), not aResult<T>. - No repository abstraction — handlers use EF Core (or your data access) directly.
What's baked in
- Target:
net10.0, nullable + implicit usings, warnings-as-errors, latest .NET analyzers + SonarAnalyzer. - Dependencies:
Kongroo.BuildingBlocks.DomainandMicrosoft.Extensions.DependencyInjection.Abstractions;IsAotCompatible. - API stability: the public surface is tracked with the public-API analyzer.
- Packaging: deterministic build, SourceLink, symbols (
snupkg), and a MinVer-derived version.
Requirements
- .NET 10 SDK or later.
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
- Kongroo.BuildingBlocks.Domain (>= 0.1.0)
- Microsoft.Extensions.DependencyInjection.Abstractions (>= 10.0.9)
NuGet packages (1)
Showing the top 1 NuGet packages that depend on Kongroo.BuildingBlocks.Application:
| Package | Downloads |
|---|---|
|
Kongroo.BuildingBlocks.Infrastructure
The EF Core and hosting building blocks for the infrastructure layer of my .NET microservices — the concretions behind the Kongroo.BuildingBlocks.Application contracts. |
GitHub repositories
This package is not used by any popular GitHub repositories.
See the project's GitHub Releases for changes.