Pragmatic.Specification 1.0.0-alpha.5

This is a prerelease version of Pragmatic.Specification.
There is a newer prerelease version of this package available.
See the version list below for details.
dotnet add package Pragmatic.Specification --version 1.0.0-alpha.5
                    
NuGet\Install-Package Pragmatic.Specification -Version 1.0.0-alpha.5
                    
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="Pragmatic.Specification" Version="1.0.0-alpha.5" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Pragmatic.Specification" Version="1.0.0-alpha.5" />
                    
Directory.Packages.props
<PackageReference Include="Pragmatic.Specification" />
                    
Project file
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 Pragmatic.Specification --version 1.0.0-alpha.5
                    
#r "nuget: Pragmatic.Specification, 1.0.0-alpha.5"
                    
#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 Pragmatic.Specification@1.0.0-alpha.5
                    
#: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=Pragmatic.Specification&version=1.0.0-alpha.5&prerelease
                    
Install as a Cake Addin
#tool nuget:?package=Pragmatic.Specification&version=1.0.0-alpha.5&prerelease
                    
Install as a Cake Tool

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 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.

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