Geaux.Specification
1.2.1
dotnet add package Geaux.Specification --version 1.2.1
NuGet\Install-Package Geaux.Specification -Version 1.2.1
<PackageReference Include="Geaux.Specification" Version="1.2.1" />
<PackageVersion Include="Geaux.Specification" Version="1.2.1" />
<PackageReference Include="Geaux.Specification" />
paket add Geaux.Specification --version 1.2.1
#r "nuget: Geaux.Specification, 1.2.1"
#:package Geaux.Specification@1.2.1
#addin nuget:?package=Geaux.Specification&version=1.2.1
#tool nuget:?package=Geaux.Specification&version=1.2.1
Geaux.Specification
A powerful, lightweight implementation of the Specification Pattern for .NET 8+ and Entity Framework Core.
Geaux.Specification enables you to express filtering, sorting, eager-loading, searching, and pagination logic as reusable, composable, testable specifications.
This package is framework-agnostic and works with any ORM or in-memory data source.
An optional companion package β Geaux.Specification.EntityFrameworkCore β provides EF Core query translation support.
β¨ Features
- π§ Encapsulate query logic into reusable specification classes
- π§© Composable criteria (Where, OrderBy, Include, Search, Pagination, etc.)
- π§ Specification Builders for fluent construction
- π Evaluators for applying specifications to query sources
- π¦ Optional EF Core integration for
IQueryable<T> - π Highly optimized & unit-test-friendly
- π§ͺ In-memory evaluator for testing
- β» Clean Architectureβfriendly & repository-compatible
π¦ Installation
Base Specification Library
dotnet add package Geaux.Specification
EF Core Integration (optional)
dotnet add package Geaux.Specification.EntityFrameworkCore
π Getting Started
Define a Specification
public class ProductsByCategory : Specification<Product>
{
public ProductsByCategory(int categoryId)
{
Query.Where(p => p.CategoryId == categoryId)
.Include(p => p.Category)
.OrderBy(p => p.Name);
}
}
Use It With a Repository
var spec = new ProductsByCategory(14);
var products = await repository.ListAsync(spec);
If using EF Core, ensure the EF evaluator is registered.
π§© Core Concepts
The library is divided into composable pieces:
ISpecification<T>
Defines all query components:
- Criteria (Where)
- Includes
- Sorting (OrderBy, OrderByDescending)
- Pagination (Skip, Take)
- Search patterns
- Caching hints
Specification<T>
The base class used to build specifications.
Key property:
protected SpecificationBuilder<T> Query { get; }
Use .Query to define:
Query.Where(x => x.Active)
.Include(x => x.Items)
.OrderBy(x => x.CreatedOn)
.Skip(10)
.Take(20);
SpecificationBuilder<T>
Fluent builder that captures all query components.
Supported operations:
WhereOrderBy,ThenByInclude,ThenIncludeSearchSkip,TakeAsNoTrackingEnableCache
π§° Evaluators
Evaluators apply specifications to query sources.
ISpecificationEvaluator
Applies specifications to EF Core IQueryable<T>:
var query = dbContext.Products.AsQueryable();
var result = EFSpecificationEvaluator.Default.GetQuery(query, spec);
Used internally by most repository implementations.
IInMemorySpecificationEvaluator
Used for unit testing without EF Core:
var result = list.AsQueryable().WithSpecification(spec);
Ensures your specifications behave consistently in memory and against EF Core.
π Search Support
The library includes a powerful search evaluator:
Query.Search(x => x.Name, "coffee");
Query.Search(x => x.Description, "%organic%");
Supports:
- SQL-like patterns
- Multi-field search
- Composable search expressions
π Pagination
Easy to express:
Query.Skip(20).Take(10);
EF Core and in-memory evaluators both honor pagination.
π Includes (Eager Loading)
Supports navigation properties:
Query.Include(p => p.Category)
.Include(p => p.Reviews);
Works seamlessly with:
- EF Core
- In-memory evaluation (ignored but validated)
π§ Builder Extensions
Extension methods provide additional helpers:
OrderByDescendingThenByDescendingIncludechainingSearchoverloadsEnableCache
π¦ Entity Framework Core Integration
Install:
dotnet add package Geaux.Specification.EntityFrameworkCore
Adds:
EFSpecificationEvaluator- EF-friendly expression processing
- Support for navigation tree building
Usage:
var result = await dbContext.Products
.WithSpecification(spec)
.ToListAsync();
π§ͺ Testing With In-Memory Evaluator
var result = new InMemorySpecificationEvaluator()
.Evaluate(productsList.AsQueryable(), spec);
Ensures business rules are tested without infrastructure dependencies.
β Repository Compatibility
Geaux.Specification is fully compatible with repository abstractions such as:
IRepository<T>IReadRepository<T>
Example:
public async Task<IReadOnlyList<Product>> ListProducts(ISpecification<Product> spec)
{
return await _repo.ListAsync(spec);
}
π Project Structure
Geaux.Specification/
β
βββ Abstractions/
β βββ ISpecification.cs
β βββ ISingleResultSpecification.cs
β βββ ISpecificationBuilder.cs
β βββ IValidator.cs
β
βββ Builders/
β βββ SpecificationBuilder.cs
β βββ OrderedSpecificationBuilder.cs
β βββ IncludableSpecificationBuilder.cs
β βββ CacheSpecificationBuilder.cs
β
βββ Evaluators/
β βββ WhereEvaluator.cs
β βββ OrderEvaluator.cs
β βββ SearchEvaluator.cs
β βββ PaginationEvaluator.cs
β βββ IncludeEvaluator.cs
β βββ InMemorySpecificationEvaluator.cs
β
βββ Exceptions/
β βββ DuplicateOrderChainException.cs
β βββ DuplicateSkipException.cs
β βββ DuplicateTakeException.cs
β βββ SelectorNotFoundException.cs
β
βββ Geaux.Specification.csproj
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net8.0 is compatible. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. net9.0 is compatible. net9.0-android was computed. net9.0-browser was computed. net9.0-ios was computed. net9.0-maccatalyst was computed. net9.0-macos was computed. net9.0-tvos was computed. net9.0-windows was computed. net10.0 was computed. 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. |
-
net8.0
- No dependencies.
-
net9.0
- No dependencies.
NuGet packages (1)
Showing the top 1 NuGet packages that depend on Geaux.Specification:
| Package | Downloads |
|---|---|
|
Geaux.SharedKernal
Foundational domain-driven building blocks for .NET applications. Provides CQRS primitives, domain events, entity base classes, value objects, repository abstractions, audit trail, and soft delete support. |
GitHub repositories
This package is not used by any popular GitHub repositories.
* Added net8.0 and net9.0 target framework
* Improved repository abstractions and evaluators