ZeroAlloc.Templates 0.17.3

dotnet new install ZeroAlloc.Templates@0.17.3
                    
This package contains a .NET Template Package you can call from the shell/command line.

ZeroAlloc.Templates

NuGet Build codecov License: MIT AOT GitHub Sponsors

dotnet new Web API templates for the ZeroAlloc.* ecosystem. Source-generated and published as Native AOT. The ZeroAlloc primitives — value objects, Result<T, E>, generated validators — allocate nothing per call, and each template's README publishes the measured cost of every framework step above them.

Catalog

Short name Architecture When to pick it
za-clean Clean Architecture — four layered projects (Domain / Application / Infrastructure / Api) with NetArchTest boundary rules Conservative shape; familiar to teams already running layered architectures; horizontal boundaries lock concerns in place
za-vertical-slice Vertical Slice Architecture — one src project, one folder per use case, one file per slice (request + validator + handler + endpoint + entity co-located) Lower-ceremony shape; each feature reads top-to-bottom in one ~50–100 line file; sharper A/B comparison against za-clean on the same domain

Both templates share nine ZeroAlloc libraries: Mediator, Validation, Authorization, Mapping, ValueObjects, Inject, Results, Serialisation and ORM. za-clean adds three more, for 12 libraries in 22 packages: Rest and Resilience for its outbound shipping-quote client, and Telemetry for the [Instrument] proxy on that client's port. za-vertical-slice has no outbound HTTP call, so it has no Rest or Resilience; it takes its telemetry from the Mediator.Telemetry pipeline behavior instead, for nine libraries in 19 packages. Each template uses the telemetry tool that fits its architecture: a layered app instruments its ports, while slices stay self-contained and the mediator pipeline instruments every request. Both share the same ZA.ORM 2 + SQLite persistence (raw Microsoft.Data.Sqlite provider, no DbContext), same xUnit + BenchmarkDotNet + NBomber test/bench fan-out. Apart from za-clean's outbound shipping-quote call, they differ in arrangement, not in functional scope — pick on team comfort, not capability.

Throughput

NativeAOT builds, Postgres 17, JWT authentication on, 256 connections, the app pinned to two performance cores. Requests per second is the median of three alternated rounds; memory is the bytes allocated per request through the whole middleware stack:

Scenario za-clean req/s za-clean alloc za-vertical-slice req/s za-vertical-slice alloc
Cache hit ~39,000 24.2 KB ~38,000 24.1 KB
Uncached read: mediator, ZA.ORM, JSON ~16,000 27.7 KB ~17,000 25.6 KB
Mixed: reads while 100 orders per second are created ~32,000 n/a ~34,000 n/a
Write ~3,300 37.9 KB ~6,800 33.9 KB

Requests per second was measured on one i9-12900HK laptop with oha, so your numbers will differ with your hardware; allocations are exact and do not depend on the machine. The two templates read at the same speed: architecture style costs nothing at run time. The read allocations were measured on SQLite and the write allocations on Postgres; the mixed scenario has no allocation benchmark. Setup, ranges, latency and caveats: docs/benchmarks/2026-11-05-template-rps.md.

Install

dotnet new install ZeroAlloc.Templates

Use

# Clean Architecture
dotnet new za-clean -o MyApp
cd MyApp && dotnet run --project src/MyApp.Api
# In another shell:
curl http://localhost:5000/healthz
# → {"status":"ok"}

# Vertical Slice
dotnet new za-vertical-slice -o MyApp
cd MyApp && dotnet run --project src/MyApp
# In another shell:
curl http://localhost:5000/healthz
# → Healthy

Options

Both templates take one option:

Option Default Effect
--EnableOpenApi true Adds the built-in .NET 10 OpenAPI document and the Scalar API reference. In the Development environment only, /openapi/v1.json serves the document and /scalar serves the reference page. false leaves out the code and the Microsoft.AspNetCore.OpenApi and Scalar.AspNetCore packages.
dotnet new za-clean -o MyApp --EnableOpenApi false

za-clean ships with:

  • Four layered projects (Domain, Application, Infrastructure, Api) with NetArchTest-enforced boundaries
  • 49 passing tests (12 unit + 5 architecture + 32 integration)
  • A BenchmarkDotNet write-pipeline scenario (36,920 B per request through the full middleware stack on SQLite, 38,551 B on Postgres; see docs/za-clean.md)
  • An NBomber read-RPS scenario for load testing under sustained concurrency
  • An AGENTS.md that orients Claude Code, Cursor, GitHub Copilot, Codex, and Aider to the codebase

za-vertical-slice ships with:

  • One src project (MyApp) — no horizontal layers; concerns live next to the feature that uses them
  • Six slices (PlaceOrder, GetOrder, ListOrders, CancelOrder, CreateCustomer, GetCustomer) with request + validator + handler + endpoint + entity co-located per *.cs file
  • 70 passing tests (37 unit + 28 integration + 5 NetArchTest convention cases over 4 rules)
  • The same BenchmarkDotNet + NBomber benchmark fan-out adapted to the flat PlaceOrderCommand shape

Full tour and rationale: docs/za-clean.md and docs/za-vertical-slice.md.

What's in the box

Paths are for za-clean; za-vertical-slice keeps the same pieces next to the slice that uses them.

Concern Package Where it lives
CQRS dispatch ZA.Mediator MyApp.Application (handlers return ValueTask<T>)
Source-generated mapping ZA.Mapping MyApp.Api/Mappings/
Validation ZA.Validation + ZA.Mediator.Validation [Validate] on the command; MyApp.Application/CreateOrder/CreateOrderValidator.cs maps the generated validator's first failure to a UnitResult<ValidationError>
Source-generated DI ZA.Inject [Scoped] / [Singleton] / [Transient] on services
Typed HTTP client ZA.Rest + ZA.Rest.SystemTextJson MyApp.Infrastructure/External/; za-clean only, za-vertical-slice makes no outbound call
Resilience ZA.Resilience + ZA.Rest.Resilience Bridged into the shipping client; za-clean only
Smart-ctor IDs/money ZA.ValueObjects MyApp.Domain/ValueObjects/
Result<T, Error> ZA.Results Across Domain + Application boundaries
Authorization ZA.Authorization + ZA.Mediator.Authorization [RequirePolicy] on commands; policies in MyApp.Application/Authorization/
JSON for value objects ZA.Serialisation + ZA.Serialisation.SystemTextJson Generated JsonConverters for the [ValueObject] ids, registered with AddZeroAllocValueObjectConverters() in MyApp.Api/Program.cs
Instrumentation ZA.Telemetry (za-clean), ZA.Mediator.Telemetry (za-vertical-slice) za-clean: [Instrument] on MyApp.Application/IShippingQuoteClient.cs; AddMyAppInfrastructure registers the generated proxy. za-vertical-slice: WithTelemetry() in AddMyApp puts the mediator's telemetry behavior in every request pipeline, so slices carry no telemetry code
Source-generated persistence ZA.ORM 2 + AdoNet.Async [Command]/[Query] partials over IAsyncDbConnection; embedded SQL migrations under Persistence/Migrations/

License

MIT — see LICENSE.

Maintaining this repo? See CONTRIBUTING.md.

  • net10.0

    • No dependencies.

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.17.3 0 11/23/2026
0.17.0 127 10/29/2026
0.16.5 126 10/23/2026
0.16.4 128 10/22/2026
0.16.3 119 10/22/2026
0.16.2 136 10/16/2026
0.16.1 123 10/15/2026
0.16.0 128 10/15/2026
0.15.18 137 10/11/2026
0.15.17 137 10/11/2026
0.15.16 168 9/27/2026
0.15.15 178 9/21/2026
0.15.14 170 9/21/2026
0.15.13 161 9/15/2026
0.15.12 236 8/10/2026
0.15.11 219 8/10/2026
0.15.10 226 8/7/2026
0.15.9 229 8/4/2026
0.15.8 250 7/28/2026
0.15.7 247 7/21/2026
Loading failed