QueryBuilderSpecs 1.1.1
dotnet add package QueryBuilderSpecs --version 1.1.1
NuGet\Install-Package QueryBuilderSpecs -Version 1.1.1
<PackageReference Include="QueryBuilderSpecs" Version="1.1.1" />
<PackageVersion Include="QueryBuilderSpecs" Version="1.1.1" />
<PackageReference Include="QueryBuilderSpecs" />
paket add QueryBuilderSpecs --version 1.1.1
#r "nuget: QueryBuilderSpecs, 1.1.1"
#:package QueryBuilderSpecs@1.1.1
#addin nuget:?package=QueryBuilderSpecs&version=1.1.1
#tool nuget:?package=QueryBuilderSpecs&version=1.1.1
QueryBuilderSpecsLibrary ๐
A powerful and clean .NET library for building query specifications using the Specification Pattern, Generic Repository, and Unit of Work.
โ Fully supports filtering via DTOs
โ Works with both EF Core DbContext and Unit of Work
โ Highly customizable and testable
๐ฆ Installation
Install via NuGet:
dotnet add package QueryBuilderSpecsLibrary
๐งฐ Features
- ๐ Unit of Work: Abstracts multiple repositories with transactional support
- ๐ Specification Pattern: Enables clean, reusable, and composable query logic
- ๐งช Filter Builder: Apply filtering rules based on DTOs dynamically
- ๐ก Generic Repository: Simplifies CRUD operations
๐ ๏ธ Setup
1. Register Library Services in Program.cs
builder.Services.UseQueryBuilderSpecs(); // Registers UoW and repository
2. Register Filter Builder for a specific entity
builder.Services.AddFilterBuilder<User, UserFilter, UserFilterBuilder>();
๐งช Usage
โ Using DbContext with Filter Builder
app.MapGet("/api/users/from-dbcontext", async (
UserFilter filter,
[FromServices] AppDbContext dbContext,
[FromServices] IGenericFiltersBuilder<User, UserFilter> filterBuilder
) =>
{
var users = await dbContext.Users
.ApplyFilter(filter, filterBuilder)
.ToListAsync();
return Results.Ok(users);
});
โ Using Unit of Work
app.MapGet("/api/users/from-uow", async (
UserFilter filter,
[FromServices] IUnitOfWork<AppDbContext> uow,
[FromServices] IGenericFiltersBuilder<User, UserFilter> filterBuilder
) =>
{
var spec = uow.Repository<User>()
.InjectSpecification(filterBuilder, filter);
var users = await uow.Repository<User>().GetAllAsync(extendQuery: spec);
return Results.Ok(users);
});
๐ Folder Structure
๐ฆ QueryBuilderSpecsLibrary
โฃ ๐ src
โ โฃ ๐ QueryBuilderSpecs.csproj
โ โฃ ๐ Interfaces/
โ โฃ ๐ Extensions/
โ โ ๐ Specifications/
โ ๐ SampleWebApp
โ ๐ Program.cs
๐ Sample DTO and Filter Builder
UserFilter.cs
public class UserFilter
{
public string? Name { get; set; }
public bool? IsActive { get; set; }
}
FilterByIsActiveSpecification.cs
public class FilterByIsActiveSpecification : BaseSpecification<User>, ISpecification<User>
{
public FilterByIsActiveSpecification(bool? isActive)
{
if (isActive == null)
return;
SetCriteria(u => u.IsActive == isActive);
}
}
UserFilterBuilder.cs
public class UserFilterBuilder: GenericFiltersBuilder<User,UserFilter>,IGenericFiltersBuilder<User,UserFilter>
{
public override void InitItemSpecifications()
{
AddSpecification(
nameof(UserFilter.Name),
filter => new FilterByNameSpecification(filter.Name)
);
AddSpecification(
nameof(UserFilter.IsActive),
filter => new FilterByIsActiveSpecification(filter.IsActive)
);
}
}
๐งช Testing
Use the sample project to test and verify functionality:
dotnet run --project SampleWebApp
Navigate to:
https://localhost:5001/swagger
Test your endpoints with filters such as:
/api/users/from-dbcontext?name=John
/api/users/from-uow?isActive=true
๐งพ Versioning
We follow Semantic Versioning:
1.0.0
โ Initial release1.1.0
โ Minor feature additions (non-breaking)1.1.1
โ Update package tags (description, tags) (non-breaking)
Update the version in .csproj
and tag it:
<Version>1.1.1</Version>
๐ License
This project is licensed under the MIT License.
๐โโ๏ธ Contributing
We welcome contributions! Feel free to open issues, PRs, or suggest improvements.
๐ Author
Developed with โค๏ธ by GibranFahed
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 was computed. 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
- Microsoft.EntityFrameworkCore (>= 9.0.5)
- Microsoft.EntityFrameworkCore.Relational (>= 9.0.5)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.