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" />
<PackageReference Include="Kongroo.BuildingBlocks.Infrastructure" />
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
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
#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
#tool nuget:?package=Kongroo.BuildingBlocks.Infrastructure&version=0.2.0
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
🦘 Kongroo.BuildingBlocks.Infrastructure
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.CommitAsyncbeforeSaveChanges, so side effects share the one transaction and integration events that handlers publish through MassTransit's bus outbox are staged in the sameSaveChanges. NoSaveChangesInterceptor— 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; yourconfigureOptionsruns 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 theAddX()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) withEFCore.NamingConventions, and theMicrosoft.Extensions.*.Abstractionsfor 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
- .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. |
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
-
net10.0
- EFCore.NamingConventions (>= 10.0.1)
- Kongroo.BuildingBlocks.Application (>= 0.1.0)
- Microsoft.EntityFrameworkCore.Relational (>= 10.0.9)
- Microsoft.Extensions.DependencyInjection.Abstractions (>= 10.0.9)
- Microsoft.Extensions.Hosting.Abstractions (>= 10.0.9)
- Microsoft.Extensions.Logging.Abstractions (>= 10.0.9)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.
See the project's GitHub Releases for changes.