Kongroo.BuildingBlocks.Infrastructure 0.2.0

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

🦘 Kongroo.BuildingBlocks.Infrastructure

CI NuGet Downloads License: MIT

Infrastructure-layer building blocks for the infrastructure layer of my .NET microservices — an EF Core unit of work that dispatches domain events before saving, a schema-per-context base, a migration initializer, and the hosted runner that orders and runs startup initializers. Builds on Kongroo.BuildingBlocks.Application and EF Core.

Installation

dotnet add package Kongroo.BuildingBlocks.Infrastructure

Building blocks

Type Purpose
UnitOfWork<TDbContext> Dispatches buffered domain events, then SaveChanges, in one commit
IRelationalDbContext Declares a context's default schema (static abstract Schema)
RelationalDbContext<TDbContext> EF Core base that applies the per-context default schema
DbInitializer<TDbContext> Applies pending migrations on startup (warns outside Development)
ApplicationInitializationService Hosted runner for IApplicationInitializers, ordered by priority
AddRelationalDbContext / AddUnitOfWork / AddApplicationInitializer / AddDbInitializer DI registration

Usage

public sealed class OrderingDbContext(DbContextOptions<OrderingDbContext> options)
    : RelationalDbContext<OrderingDbContext>(options), IRelationalDbContext
{
    public static string Schema => "ordering";

    public DbSet<Order> Orders => Set<Order>();

    protected override void OnModelCreating(ModelBuilder modelBuilder)
    {
        base.OnModelCreating(modelBuilder); // applies the "ordering" schema
        modelBuilder.Entity<Order>(order =>
        {
            order.HasKey(entity => entity.Id);
            order.Property(entity => entity.Id).HasConversion(id => id.Value, value => OrderId.From(value));
        });
    }
}

// Registration
services.AddApplication();
services.AddRelationalDbContext<OrderingDbContext>(options => options.UseNpgsql(connectionString));
services.AddDbInitializer<OrderingDbContext>();

// In a command handler
order.Place();              // buffers an OrderPlaced domain event
dbContext.Orders.Add(order);
await unitOfWork.CommitAsync(cancellationToken); // dispatch OrderPlaced, then persist

Design notes

  • Dispatch before save: domain events are dispatched in UnitOfWork.CommitAsync before SaveChanges, so side effects share the one transaction and integration events that handlers publish through MassTransit's bus outbox are staged in the same SaveChanges. No SaveChangesInterceptor — it conflicts with MassTransit's EF outbox.
  • MassTransit owns messaging: the integration-event outbox/inbox lives at the app level; this package ships nothing for it.
  • Explicit strongly-typed-id conversions: configure them per-property in your IEntityTypeConfiguration<T> files.
  • Opinionated AddRelationalDbContext: applies snake_case naming and, in Development, EF Core detailed errors and sensitive-data logging; your configureOptions runs last, so you can override.
  • One namespace: the DI extensions live in the package namespace, so a single using Kongroo.BuildingBlocks.Infrastructure; brings the types and the AddX() helpers.

What's baked in

  • Target: net10.0, nullable + implicit usings, warnings-as-errors, latest .NET analyzers + SonarAnalyzer.
  • Dependencies: Kongroo.BuildingBlocks.Application (→ Domain), EF Core (Relational) with EFCore.NamingConventions, and the Microsoft.Extensions.*.Abstractions for hosting, logging, and DI.
  • API stability: the public surface is tracked with the public-API analyzer.
  • Packaging: deterministic build, SourceLink, symbols (snupkg), and a MinVer-derived version.

Requirements

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
0.2.0 149 6/28/2026
0.1.0 112 6/28/2026

See the project's GitHub Releases for changes.