đī¸ ApiController Documentation
QUICK DOCUMENTATIONâ
- File Path:
/API/Controllers/ApiController.cs - Primary Purpose: Serves as the base controller class for all API controllers in the APV system
- Key Features:
- Provides access to MediatR for CQRS pattern implementation
- Implements common authorization and routing settings
- Configures request size limits
- Related Components:
- All other controllers in the API namespace inherit from this class
- Used By:
- Every API controller in the APV system
đ Business Contextâ
The ApiController serves as the foundation for the entire API layer of Asset Valuer Pro. It implements the Command Query Responsibility Segregation (CQRS) pattern referenced in the Technical Audit and Documentation Strategy, providing a consistent approach to handling API requests across the system.
DETAILED DOCUMENTATIONâ
đ Overviewâ
ApiController is an abstract base class that all other API controllers in the Asset Valuer Pro system inherit from. It encapsulates common functionality such as authentication requirements, request size limits, and access to the MediatR mediator for handling commands and queries. This design promotes consistency across the API layer and implements the CQRS pattern for separating command and query responsibilities.
đī¸ Controller Dependenciesâ
- Namespace:
AVP.API.Controllers - Services Used:
ISender(MediatR): For sending commands and queriesIBusRegistry(Rebus): For message bus operations
- Other Dependencies:
Microsoft.AspNetCore.Authorization: For authentication requirementsMicrosoft.AspNetCore.Mvc: For API controller functionality
đ§ Class Detailsâ
Attributesâ
- đ
[Authorize]: Requires authentication for all derived controllers - đ
[ApiController]: Enables API-specific behavior - âĄ
[DisableRequestSizeLimit]: Removes request size restrictions - đ
[Route("api/[controller]")]: Sets up conventional routing based on controller name
Propertiesâ
- đ§
Mediator: Protected property providing access to the MediatR mediator - đ§
BusRegistry: Protected property providing access to the Rebus message bus registry
đĄ Implementation Notesâ
- âšī¸ The controller uses lazy initialization for its dependencies, resolving them from the DI container on first access
- â All request handling is delegated to MediatR, keeping controllers thin and focused on HTTP concerns
- đ§ The use of
ControllerBaserather thanControllerindicates this is an API-only controller without view support - â ī¸ Setting
DisableRequestSizeLimitallows for uploads of any size, which may require monitoring in production
đ Usage Exampleâ
// Example of inheriting from ApiController
public class AssetController : ApiController
{
[HttpGet]
[Route("Get")]
public async Task<AssetDto> GetAsset([FromQuery] GetAssetQuery query)
{
// Uses the Mediator property from ApiController
return await Mediator.Send(query);
}
}
đ Security Considerationsâ
- The
[Authorize]attribute ensures that all API endpoints require authentication by default - Individual controllers or actions can override this behavior if needed
- No specific roles are required at this level, allowing more granular access control in derived controllers