The Specification Pattern allows you to encapsulate a piece of business logic (usually a filter or validation rule) into a reusable class.
Instead of writing .Where(o => o.IsPaid && o.Status == 2) in 5 different places, you create a PendingOrdersSpecification. You can then pass this specification to your repository. This ensures that the 'Definition' of a pending order is centralized in the Domain layer.
Specifications can be combined using And(), Or(), and Not(). This allows you to build complex business rules out of simple, testable blocks. var spec = new OverdueSpec().And(new HighValueSpec());. It translates perfectly to EF Core Expression trees for high-performance database queries.
Q: "When should I use Specifications?"
Architect Answer: "Use them when a boolean business rule is reused in multiple places (filtering a list, validating a single entity, or even determining if a discount applies). It prevents the 'Copy-Paste' of business logic and ensures your domain invariants are enforced consistently across the whole system."