Specification pattern · C# 14

Business rules that read like business rules.

Compose named rules with terse, discoverable syntax—then evaluate them in memory or hand them to infrastructure without leaking a query API.

OrderService.csNo operators
public static Spec<Order> ReadyToShip() =>
    CanShip.And.HighPriority.AndNot.Suspended;

A deliberately small idea

Readable at the call site. Honest at the boundary.

01

Domain-first syntax

`CanShip.And.HighPriority` says what the rule means without ceremony or overloaded Boolean operators.

02

One rule tree

The same immutable specification supports fast matching, structured diagnostics, rendering, and translation.

03

No query leakage

Repositories accept `Spec<T>`. EF Core stays in infrastructure and materializes results before returning.

The useful boundary

Boolean rules in. Materialized answers out.

A specification does not carry sorting, paging, projections, includes, or tracking flags. Those are repository decisions—not Boolean rules.

Understand the EF Core boundary