Pragmatic.Specification
1.0.0-alpha.3
See the version list below for details.
dotnet add package Pragmatic.Specification --version 1.0.0-alpha.3
NuGet\Install-Package Pragmatic.Specification -Version 1.0.0-alpha.3
<PackageReference Include="Pragmatic.Specification" Version="1.0.0-alpha.3" />
<PackageVersion Include="Pragmatic.Specification" Version="1.0.0-alpha.3" />
<PackageReference Include="Pragmatic.Specification" />
paket add Pragmatic.Specification --version 1.0.0-alpha.3
#r "nuget: Pragmatic.Specification, 1.0.0-alpha.3"
#:package Pragmatic.Specification@1.0.0-alpha.3
#addin nuget:?package=Pragmatic.Specification&version=1.0.0-alpha.3&prerelease
#tool nuget:?package=Pragmatic.Specification&version=1.0.0-alpha.3&prerelease
Pragmatic.Specification
The specification pattern for composable, reusable query predicates in .NET 10.
The Problem
Business rules embedded in queries get duplicated across repositories, services, and validators, each copy an inline lambda. Change the rule and you hunt every method; worse, SQL (expression trees) and in-memory checks (compiled delegates) drift apart.
db.Orders.Where(o => !o.IsCancelled && !o.IsDeleted) // repository
db.Orders.Where(o => !o.IsCancelled && !o.IsDeleted && o.Total >= t) // service: same rule again
!order.IsCancelled && !order.IsDeleted // validator: same rule, drifts
The Solution
Encapsulate a rule once as a Specification<T>, compose with And/Or/Not, and use the same
specification for EF Core queries (translated to SQL) and in-memory checks (IsSatisfiedBy).
public sealed class ActiveOrder : Specification<Order>
{
public override Expression<Func<Order, bool>> ToExpression()
=> o => !o.IsCancelled && !o.IsDeleted;
}
db.Orders.Where(new ActiveOrder().And(new OrderOverThreshold(100m))); // → SQL
bool ok = new ActiveOrder().IsSatisfiedBy(order); // in-memory, same rule
One definition, reusable and independently unit-testable; dynamic filters compose without if-chains.
Installation
dotnet add package Pragmatic.Specification
Status
Stable within 1.0.0-alpha: composition (And/Or/Not), EF Core translation, and in-memory
evaluation are settled. See the roadmap.
Documentation
| Guide | What you'll learn |
|---|---|
| Concepts | The pattern, expression vs delegate, when to use it |
| Getting Started | Your first specification, querying, in-memory checks |
| Composition Patterns | And/Or/Not, dynamic filters from user input, reusable building blocks |
| Common Mistakes | The most frequent specification pitfalls |
| Troubleshooting | Problem/solution guide |
Requirements
- .NET 10.0+
License
Part of the Pragmatic.Design ecosystem. See Licensing. Pragmatic.Specification is MIT-licensed.
| 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. |
-
net10.0
- Pragmatic.Abstractions (>= 1.0.0-alpha.3)
- Pragmatic.Ensure (>= 1.0.0-alpha.3)
NuGet packages (1)
Showing the top 1 NuGet packages that depend on Pragmatic.Specification:
| Package | Downloads |
|---|---|
|
Pragmatic.Persistence
Persistence abstractions for Pragmatic.Design - Entity definitions, Repository pattern, UnitOfWork, and DTO-driven Query/Mutation patterns. Database-agnostic, works with any ORM. |
GitHub repositories
This package is not used by any popular GitHub repositories.
| Version | Downloads | Last Updated |
|---|---|---|
| 1.0.0-alpha.6 | 310 | 11/21/2026 |
| 1.0.0-alpha.5 | 237 | 11/21/2026 |
| 1.0.0-alpha.4 | 300 | 11/16/2026 |
| 1.0.0-alpha.3 | 625 | 10/17/2026 |
| 1.0.0-alpha.2 | 233 | 10/12/2026 |
| 1.0.0-alpha.1 | 465 | 10/3/2026 |