See More

A very common reason is a wrong site baseUrl configuration.\n

Current configured baseUrl = / (default value)\n

We suggest trying baseUrl = \n\n',document.body.prepend(n);var e=document.getElementById("__docusaurus-base-url-issue-banner-suggestion-container"),s=window.location.pathname,o="/"===s.substr(-1)?s:s+"/";e.textContent=o}document.addEventListener("DOMContentLoaded",function(){void 0===window.docusaurus&&insertBanner()})

Skip to main content

ZeroAlloc.Specification

ZeroAlloc.Specification is a source-generated, zero-allocation implementation of the Specification pattern for .NET 8+.

Why ZeroAlloc.Specification?

The classic DDD Specification pattern allocates heap objects on every composition — And, Or, and Not return new wrapper class instances, and delegate-based predicates create closures. In hot paths this adds GC pressure.

ZeroAlloc.Specification uses a Roslyn incremental source generator to emit And<TOther>(), Or<TOther>(), and Not() methods directly onto your spec struct. Composed types are concrete readonly struct types — no heap allocation, no closures.

Key Properties

  • Zero allocations — composed specs are structs, not classes
  • EF Core compatible — every spec exposes ToExpression() returning Expression<Func<T, bool>>
  • Compile-time safety — ZA001–ZA004 diagnostics enforce correct usage
  • Familiar API — fluent (.And(), .Or(), .Not()) and static builder (Spec.And(), Spec.Or(), Spec.Not())
  • .NET 8+ — uses C# 12 features throughout

Packages

PackagePurpose
ZeroAlloc.SpecificationCore interfaces and combinator structs
ZeroAlloc.Specification.GeneratorRoslyn source generator (auto-referenced)