CleanArch.Specification
0.3.1
dotnet add package CleanArch.Specification --version 0.3.1
NuGet\Install-Package CleanArch.Specification -Version 0.3.1
<PackageReference Include="CleanArch.Specification" Version="0.3.1" />
<PackageVersion Include="CleanArch.Specification" Version="0.3.1" />
<PackageReference Include="CleanArch.Specification" />
paket add CleanArch.Specification --version 0.3.1
#r "nuget: CleanArch.Specification, 0.3.1"
#:package CleanArch.Specification@0.3.1
#addin nuget:?package=CleanArch.Specification&version=0.3.1
#tool nuget:?package=CleanArch.Specification&version=0.3.1
CleanArchitecture Specification
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, andNotoperators. - Supports LINQ: Integrates seamlessly with Entity Framework, LINQ to Objects, or any
IQueryableprovider. - 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 | Versions 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. |
-
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 |