specification-pattern

Encapsulate reusable and composable query criteria for EF Core repositories.

Updated Apr 4, 2026
One-click install
npx skills add https://github.com/hiiamsky/multi-agent-dev-team --skill specification-pattern-hiiamsky
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: specification-pattern
Source: https://github.com/hiiamsky/multi-agent-dev-team/tree/main/.github/skills/dotnet-specification-pattern
Command: npx skills add https://github.com/hiiamsky/multi-agent-dev-team --skill specification-pattern-hiiamsky

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

The Specification pattern encapsulates query logic into reusable, composable criteria that can be combined and tested in isolation, enabling clean data access in C#/.NET applications.

Core Features & Use Cases

  • Reusable criteria: define a base query once and reuse across multiple repositories.
  • Composability: combine criteria with And/Or to form complex filters.
  • Type-safe and testable: compile-time checks while allowing unit tests of query logic.
  • EF Core integration: works with SpecificationEvaluator to apply includes, ordering, and paging.

Quick Start

Create a concrete specification by extending BaseSpecification<T>, configure Criteria and Includes, and pass it to a repository to execute the query.

Frequently Asked Questions about specification-pattern

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I encapsulate reusable query criteria for EF Core repositories?

You can encapsulate reusable query criteria by creating a concrete specification that extends BaseSpecification<T>, configuring Criteria and Includes, and passing it to a repository for execution in EF Core.

What is the specification pattern in C# and when should I use it?

The specification pattern in C# encapsulates query logic into reusable, composable criteria that can be combined and tested in isolation, enabling clean data access when you have advanced filtering, includes, ordering, and paging requirements.

How do I combine multiple query filters with And/Or logic in .NET?

You can combine multiple query filters by composing criteria with And/Or operations to form complex filters, allowing type-safe, testable query logic that integrates with the SpecificationEvaluator in your .NET applications.

Does the specification pattern support paging and ordering with LINQ?

Yes, the specification pattern supports paging and ordering by applying includes, ordering, and paging criteria through the SpecificationEvaluator, which integrates with LINQ and EF Core for domain queries.

How do I unit test query logic separately from the repository in C#?

You can unit test query logic separately by encapsulating it into composable criteria that are type-safe and testable in isolation, ensuring compile-time checks while validating query logic without hitting the database.

What's the best way to handle advanced domain queries across multiple repositories?

The best way to handle advanced domain queries across multiple repositories is to define a base query once using a specification and reuse those composable criteria, ensuring clean data access and consistent filtering across your .NET application.