How gmrodriguez12/webapi-onion works
This is an Onion-architecture .NET 6 Web API template for CRUD operations on AdventureWorks products. A client sends product requests to the versioned API; the controller dispatches MediatR commands or queries, whose handlers use repository abstractions and return response DTOs. Listing adds subcategory filtering and pagination. The README documents pipeline validation, FluentValidation, AutoMapper, CQRS, MediatR, Ardalis.Specification, and EF Core database-first mapping. The graph shows documented and indexed relationships; unsampled validator wiring and some persistence details are not asserted.
Main entry points: ProductController.cs Product controller · GetAllProductsQuery.cs List products · Commands Product commands · GetProductByIdQuery.cs Get product
Components 21
HTTP API
- Product controller
WebAPI/Controllers/v1/ProductController.cs - MediatR access
WebAPI/Controllers/BaseApiController.cs - Error middleware
WebAPI/Middleware/ErrorHandlerMiddleware.cs
Application workflow
- Product commands
Application/Features/Products/Commands - Get product
Application/Features/Products/Queries/GetProductByIdQuery/GetProductByIdQuery.cs - List products
Application/Features/Products/Queries/GetAllProductsQuery/GetAllProductsQuery.cs - Validation behavior
Application/Beheaviors/ValidationBehavior.cs - Application registration
Application/ServiceExtensions.cs - Product mapping
Application/Mappings/GeneralProfile.cs - Product DTO
Application/DTOs/ProductDTO.cs - Paged specification
Application/Specifications/PagedProductSpecification.cs - Repository abstraction
Application/Interfaces/IRepositoryAsync.cs - Response wrappers
Application/Wrappers/Response.cs - Paged response
Application/Wrappers/PagedResponse.cs - Command validators
Application/Features/Products/Commands
Persistence
- Async repository
Persistence/Repository/AdventureRepositoryAsync.cs - EF Core context
Persistence/Data/AdventureWorkDbContext.cs - AdventureWorks database
AdventureWorks domain
- Product entity
Domain/Entities/Product.cs - AdventureWorks entities
Domain/Entities
Other components
- API client
Connections 23
- API client → Product controller: sends requests
WebAPI/Controllers/v1/ProductController.cs - Product controller → MediatR access: uses mediator
WebAPI/Controllers/v1/ProductController.cs - Product controller → Product commands: dispatches commands
WebAPI/Controllers/v1/ProductController.cs - Product controller → Get product: dispatches query
WebAPI/Controllers/v1/ProductController.cs - Product controller → List products: dispatches query
WebAPI/Controllers/v1/ProductController.cs - Product commands → Repository abstraction: uses repository
Application/Features/Products/Commands/CreateProductCommand/CreateProductCommand.cs - Product commands → Product entity: manages entity
Application/Features/Products/Commands/CreateProductCommand/CreateProductCommand.cs - Product commands → Response wrappers: returns wrapper
Application/Features/Products/Commands/CreateProductCommand/CreateProductCommand.cs - Get product → Repository abstraction: loads product
Application/Features/Products/Queries/GetProductByIdQuery/GetProductByIdQuery.cs - Get product → Product mapping: maps result
Application/Features/Products/Queries/GetProductByIdQuery/GetProductByIdQuery.cs - Get product → Response wrappers: returns wrapper
Application/Features/Products/Queries/GetProductByIdQuery/GetProductByIdQuery.cs - List products → Repository abstraction: lists products
Application/Features/Products/Queries/GetAllProductsQuery/GetAllProductsQuery.cs - List products → Paged specification: applies paging
Application/Features/Products/Queries/GetAllProductsQuery/GetAllProductsQuery.cs - List products → Product mapping: maps results
Application/Features/Products/Queries/GetAllProductsQuery/GetAllProductsQuery.cs - List products → Paged response: returns page
Application/Features/Products/Queries/GetAllProductsQuery/GetAllProductsQuery.cs - Product mapping → Product DTO: maps to DTO
Application/Mappings/GeneralProfile.cs - Async repository → Repository abstraction: implements interface
Persistence/Repository/AdventureRepositoryAsync.cs - Async repository → EF Core context: uses context
Persistence/Repository/AdventureRepositoryAsync.cs - EF Core context → AdventureWorks entities: maps entities
Persistence/Data/AdventureWorkDbContext.cs - EF Core context → AdventureWorks database: reads and writes
- Application registration → Validation behavior: registers behavior
Application/ServiceExtensions.cs - Command validators → Validation behavior: validated by pipeline
- Error middleware → Response wrappers: builds error response
WebAPI/Middleware/ErrorHandlerMiddleware.cs