CleanArch.Specification 0.3.1

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

CleanArchitecture Specification

NuGet

CleanArch.Specification is a lightweight and flexible Specification pattern library for .NET applications following Clean Architecture principles. It allows developers to encapsulate complex business rules and query logic into reusable, composable, and testable specifications, keeping your domain and application layers clean and maintainable.


✨ Features

  • Encapsulate business rules: Express complex query logic and conditions in a clear, reusable manner.
  • Composable specifications: Easily combine multiple specifications using And, Or, and Not operators.
  • Supports LINQ: Integrates seamlessly with Entity Framework, LINQ to Objects, or any IQueryable provider.
  • Clean Architecture ready: Perfect for layering your domain and application code according to best practices.

📦 Installation

Install via NuGet:

dotnet add package CleanArch.Specification

Or via the Package Manager:

Install-Package CleanArch.Specification

🚀 Usage

1. Defining a Specification

using CleanArch.Specification;
using YourProject.Domain.Entities;

public class ActiveUsersSpecification : Specification<User>
{
    public ActiveUsersSpecification()
    {
        Query.Where(user => user.IsActive);
    }
}

2. Combining Specifications

var activeUsers = new ActiveUsersSpecification();
var premiumUsers = new Specification<User>();
premiumUsers.Query.Where(u => u.IsPremium);

var activePremiumUsers = activeUsers.And(premiumUsers);

3. Using Specifications with LINQ

using YourProject.Infrastructure.Persistence;

var specification = new ActiveUsersSpecification();
var users = await dbContext.Users
    .Where(specification)
    .ToListAsync();

4. Negating a Specification

var inactiveUsers = specification.Not();
var result = await dbContext.Users
    .Where(inactiveUsers)
    .ToListAsync();

📚 Why Use Specification Pattern?

  • Keeps business logic separated from infrastructure code.
  • Reusability: Define a rule once, use it everywhere.
  • Testability: Specifications can be unit tested independently.
  • Flexibility: Easily combine rules for more complex queries.

🤝 Contributing

Contributions are welcome! Feel free to submit issues or pull requests. Please follow standard GitHub workflow and ensure code is well-documented and tested.


📄 License

This project is licensed under the MIT License. See the LICENSE file for details.

Product Compatible and additional computed target framework versions.
.NET net10.0 is compatible.  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.
  • net10.0

    • No dependencies.

NuGet packages (2)

Showing the top 2 NuGet packages that depend on CleanArch.Specification:

Package Downloads
CleanArch.Domain.Abstractions

Domain abstractions for Clean Architecture.

CleanArch.Repository

Domain abstractions for Clean Architecture.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
0.3.1 509 12/11/2025