Skip to content

Glossary

Definitions and code examples of key terms used in this tutorial.

The identity element of Specification. Returns true for all candidates and is used as the starting point for And composition. Serves as the initial seed in dynamic filter chaining.

var spec = Specification<Product>.All;
spec &= new ActiveProductSpec();

A Specification that satisfies all candidates. Inherits from ExpressionSpecification<T> and provides ToExpression() => _ => true, enabling Expression extraction via SpecificationExpressionResolver.TryResolve(). Accessed through the Specification<T>.All property, it is an internal class implemented with the singleton pattern.

A composition operation that combines two Specifications, passing only candidates that satisfy both.

var spec = new ActiveProductSpec().And(new ProductInStockSpec());
// Or using operator: new ActiveProductSpec() & new ProductInStockSpec()

Combining multiple Specifications with And, Or, Not to create complex rules. The core value of the Specification pattern.


An optimization technique in ExpressionSpecification that compiles the Expression Tree only once and caches the resulting delegate.


A representation of code as a data structure. In the form of Expression<Func<T, bool>>, it can be converted by ORMs to SQL and other query languages.

Expression<Func<Product, bool>> expr = p => p.IsActive;

An abstract Specification class that supports Expression Trees. Implementing ToExpression causes IsSatisfiedBy to automatically cache the compiled delegate.

An interface indicating the ability to provide an Expression Tree. ExpressionSpecification<T> implements this, and SpecificationExpressionResolver.TryResolve() checks for this interface via pattern matching.


An element in a composition operation that does not change the other operand’s value. Specification<T>.All is the identity element for the And operation.

The core method of Specification. Determines whether a candidate object satisfies the rule and returns bool.

public override bool IsSatisfiedBy(Product candidate) =>
candidate.IsActive;

A composition operation that inverts the result of a Specification.

var spec = new ActiveProductSpec().Not();
// Or using operator: !new ActiveProductSpec()

A composition operation that passes if at least one of two Specifications is satisfied.

var spec = new PremiumSpec().Or(new DiscountedSpec());
// Or using operator: new PremiumSpec() | new DiscountedSpec()

An ExpressionVisitor that unifies different parameter expressions into one when composing Expression Trees. Used internally in And and Or compositions.

A class that defines property mappings between domain models and database entities. Used to convert domain properties to entity properties in Expression Trees.


A pattern that abstracts data access logic. When combined with Specification, a single FindAsync(spec) method enables querying with various conditions.


An abstract class that encapsulates business rules. Implements the IsSatisfiedBy method to determine whether a candidate object satisfies the criteria.

A utility that recursively synthesizes Expression Trees from multiple Specifications. Merges And, Or, Not composition Expressions into a single Expression Tree.


The core method of ExpressionSpecification. Returns the rule in Expression<Func<T, bool>> form, which ORMs can convert to SQL.

An ExpressionVisitor that transforms property accesses in Expression Trees based on PropertyMap. Converts domain model-based Expressions to database entity-based Expressions.

The core method of SpecificationExpressionResolver. Extracts an Expression Tree from a Specification and recursively synthesizes them for composed Specifications.


Check the references.

-> D. References