Geaux.Specification 1.2.1

dotnet add package Geaux.Specification --version 1.2.1
                    
NuGet\Install-Package Geaux.Specification -Version 1.2.1
                    
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="Geaux.Specification" Version="1.2.1" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Geaux.Specification" Version="1.2.1" />
                    
Directory.Packages.props
<PackageReference Include="Geaux.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 Geaux.Specification --version 1.2.1
                    
#r "nuget: Geaux.Specification, 1.2.1"
                    
#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 Geaux.Specification@1.2.1
                    
#: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=Geaux.Specification&version=1.2.1
                    
Install as a Cake Addin
#tool nuget:?package=Geaux.Specification&version=1.2.1
                    
Install as a Cake Tool

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:

  • Where
  • OrderBy, ThenBy
  • Include, ThenInclude
  • Search
  • Skip, Take
  • AsNoTracking
  • EnableCache

🧰 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:

  • OrderByDescending
  • ThenByDescending
  • Include chaining
  • Search overloads
  • EnableCache

🚦 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 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. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
  • 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.

Version Downloads Last Updated
1.2.1 318 12/17/2025
1.2.0 358 12/17/2025

* Added net8.0 and net9.0 target framework
* Improved repository abstractions and evaluators