Dangl.Data.Shared
This solution builds both Dangl.Data.Shared and Dangl.Data.Shared.AspNetCore packages.
The aim of this solution is to consolidate simple, reused code such as ApiError
or RepositoryResult<T>
.
Link to docs:
ModelStateValidationFilter
The ModelStateValidationFilter
is a simple wrapper that returns a BadRequestObjectResult
with an ApiError
body when the passed ModelState
of an action is invalid. This allows to keep controlls free of basic model state validation logic.
To use the filter, it must be configured in the AddMvc()
call in ConfigureServices
:
services.AddMvc(options =>
{
options.Filters.Add(typeof(ModelStateValidationFilter));
})
RequiredFormFileValidationFilter
The RequiredFormFileValidationFilter
is a simple wrapper that returns a BadRequestObjectResult
with an ApiError
body when the invoked
Controller action as paramaters of type IFormFile
that are annotated with [Required]
but have no value bound.
For example, the following action makes use of the filter:
[HttpPost("RequiredFormFile")]
public IActionResult RequiredFormFile([Required]IFormFile formFile)
{
return Ok();
}
To use the filter, it must be configured in the AddMvc()
call in ConfigureServices
:
services.AddMvc(options =>
{
options.Filters.Add(typeof(RequiredFormFileValidationFilter));
})
BiggerThanZeroAttribute
The BiggerThanZeroAttribute
is a ValidationAttribute
that can be applied to int
properties to ensure their values are greater than zero.