Class ControllerBase<TModel, TDto>
- Namespace
- Magicalizer.Api.Controllers
- Assembly
- Magicalizer.dll
Base of the controllers of models (the magicalized ones and the custom ones): converts models to DTOs and processes the requests around the actions, so the actions only call the services:
- The requests are validated before the actions: the errors of the query parameter names (QueryStringValidationFilterAttribute), their values (e.g. the property paths of the sortings and inclusions are checked while they are bound) and the DTOs (FluentValidationFilterAttribute) are collected, and ApiControllerAttribute returns 400 Bad Request with all of them.
- The exceptions of the services are converted to 400, 404 or 409 responses (ModelExceptionFilterAttribute).
The DTOs are created by their constructors that take the models, so a DTO only for reading (without IDto<TModel>) is enough for a custom controller that doesn't create or update models.
[ApiController]
[QueryStringValidationFilter]
[FluentValidationFilter]
public abstract class ControllerBase<TModel, TDto> : ControllerBase where TModel : class, IModel where TDto : class, IDto
Type Parameters
TModelModel type.
TDtoDTO type.
- Inheritance
-
ControllerBase<TModel, TDto>
- Derived
- Inherited Members
Methods
ModelToDto(TModel?)
Converts the model to the DTO.
protected virtual TDto? ModelToDto(TModel? model)
Parameters
modelTModelModel to convert.
Returns
- TDto
DTO, or
nullif the model isnull.