CleanArchAcceleratorTools.Controller
1.0.1
dotnet add package CleanArchAcceleratorTools.Controller --version 1.0.1
NuGet\Install-Package CleanArchAcceleratorTools.Controller -Version 1.0.1
<PackageReference Include="CleanArchAcceleratorTools.Controller" Version="1.0.1" />
<PackageVersion Include="CleanArchAcceleratorTools.Controller" Version="1.0.1" />
<PackageReference Include="CleanArchAcceleratorTools.Controller" />
paket add CleanArchAcceleratorTools.Controller --version 1.0.1
#r "nuget: CleanArchAcceleratorTools.Controller, 1.0.1"
#:package CleanArchAcceleratorTools.Controller@1.0.1
#addin nuget:?package=CleanArchAcceleratorTools.Controller&version=1.0.1
#tool nuget:?package=CleanArchAcceleratorTools.Controller&version=1.0.1
CleanArchAcceleratorTools.Controller
This module is part of CleanArchAcceleratorTools, a toolkit to accelerate building applications with Clean Architecture. The Controller module contains controllers to expose endpoints, handling HTTP requests and responses. It references the Application layer to delegate business logic and data operations.
Related modules:
- CleanArchAcceleratorTools.Application
- CleanArchAcceleratorTools.Domain
- CleanArchAcceleratorTools.Infrastructure
- CleanArchAcceleratorTools.AllInOne
📄 License: MIT
🧠 Principles
🔗 Role in the architecture
- Controller: Exposes endpoints, it does not contain business rules.
- Application: Orchestrates use cases and references the Domain and repository.
- Domain: Pure domain with business rules and validations.
- Infrastructure: Implements persistence/mapping for Domain entities.
- Mediator: Handles commands, queries, and notifications.
✨ Features
Repositories methods through application dependency injection
- Dynamic Selects – Project typed objects based on property names.
- Dynamic Filtering – Filter queries with a fluent builder using clauses and operators.
- Dynamic Sort – Sort queries with multiple fields and directions.
- Pagination Utilities – Helpers for
IQueryableincluding filtering and ordering. - Repositories Methods - Use all repositories methods only calling the application layer in your controller.
- Extensible & Lightweight – Modular, discoverable, and easy to integrate.
Global Exception filtering
- Exception Handling Middleware – Centralized exception handling for consistent error responses.
Access to Application ViewModels
- DynamicFilterViewModel – Class for building dynamic filters for queries.
- DynamicSortViewModel – Class for building dynamic sort orders for queries.
- EntityViewModel base Class for domain entities with common properties.
- PaginationResultViewModel – Class for paginated query results.
- QueryFilterViewModel – Class for encapsulating query filter parameters used in pagination.
🧩 Compatibility
Multi-target:
- .NET 6
- .NET 7
- .NET 8
- .NET 9
Use an EF Core version compatible with your target framework.
🚀 Installation
dotnet add package CleanArchAcceleratorTools.Controller --version 1.0.0
⚡ Quickstart
- Create your controllers inheriting from
GenericController<TEntity, TEntityViewModel>. - Create the enpoints.
- Use the application service methods in your controller actions.
- Create your custom methods if needed.
- Enjoy all features provided!
🛠️ Usage Examples
Configuring global exception filter and NewtonsoftJson (optional)
builder.Services.AddControllers(options =>
{
options.Filters.Add(typeof(ExceptionFilter)); // Register ExceptionFilter globally
}).AddNewtonsoftJson(config =>
{
config.SerializerSettings.ReferenceLoopHandling = ReferenceLoopHandling.Ignore;
config.SerializerSettings.Formatting = Formatting.Indented;
config.SerializerSettings.NullValueHandling = NullValueHandling.Ignore;
});
Creating a controller
[ApiController]
[Route("courses")]
public class CoursesController : GenericController<Course, CourseViewModel>
{
private readonly ICourseApplicationService _courseApplicationService;
public CoursesController(
ICleanArchMediator mediator,
INotificationHandler<DomainNotificationEvent> notificationHandler,
IApplicationLogger applicationLogger,
ICourseApplicationService courseApplicationService
) : base(courseApplicationService, mediator, notificationHandler, applicationLogger)
{
_courseApplicationService = courseApplicationService;
}
[HttpPost("search-with-pagination")]
public async Task<IActionResult> SearchWithPaginationAsync(QueryFilterViewModel<CourseViewModel> queryFilterViewModel)
{
var result = await _courseApplicationService.SearchWithPaginationAsync(queryFilterViewModel);
return ResponseResult(result);
}
}
...
// Usage
curl -X 'POST' \
'http://localhost:<you-port>/courses/search-with-pagination' \
-H 'accept: */*' \
-H 'Content-Type: application/json-patch+json' \
-d '{
"page": 0,
"pageSize": 0,
"fields": [
"string"
],
"dynamicFilter": {
"quickSearch": "string",
"clauseGroups": [
{
"logicOperator": "string",
"clauses": [
{
"logicOperator": "string",
"field": "string",
"comparisonOperator": "string",
"value": "string"
}
]
}
]
},
"dynamicSort": {
"fieldsOrder": [
{
"field": "string",
"order": "string"
}
]
}
}'
📚 Example Project
See the - CleanArchAcceleratorTools.Examples project for a complete working example, including setup and advanced scenarios. It implements a fully working API with all other modules implemented.
🧠 Tips
- Prefer
DynamicSelectto reduce materialization and network payloads. - Centralize selection fields in a constant for reuse as in CourseSelects.
🤝 Contributing
Contributions are welcome! Open issues or submit PRs for features, bug fixes, or documentation improvements. Contributing guidelines are under construction.
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net6.0 is compatible. net6.0-android was computed. net6.0-ios was computed. net6.0-maccatalyst was computed. net6.0-macos was computed. net6.0-tvos was computed. net6.0-windows was computed. net7.0 is compatible. net7.0-android was computed. net7.0-ios was computed. net7.0-maccatalyst was computed. net7.0-macos was computed. net7.0-tvos was computed. net7.0-windows was computed. 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. |
-
net6.0
- CleanArchAcceleratorTools.Application (>= 1.0.1)
- Microsoft.AspNetCore.Mvc (>= 2.3.0)
-
net7.0
- CleanArchAcceleratorTools.Application (>= 1.0.1)
- Microsoft.AspNetCore.Mvc (>= 2.3.0)
-
net8.0
- CleanArchAcceleratorTools.Application (>= 1.0.1)
- Microsoft.AspNetCore.Mvc (>= 2.3.0)
-
net9.0
- CleanArchAcceleratorTools.Application (>= 1.0.1)
- Microsoft.AspNetCore.Mvc (>= 2.3.0)
NuGet packages (1)
Showing the top 1 NuGet packages that depend on CleanArchAcceleratorTools.Controller:
| Package | Downloads |
|---|---|
|
CleanArchAcceleratorTools.AllInOne
This module is part of CleanArchAcceleratorTools, a toolkit to accelerate building applications with Clean Architecture. |
GitHub repositories
This package is not used by any popular GitHub repositories.