Library of standards implemented to use in ASP.NET Core.
For example, it provides convenient abstractions for enforcing DateTime
objects are binded with ISO-8601 format (YYYY-MM-DD) in MVC.
Standards.AspNetCore currently targets .NET 6+. We follow the .NET Core support policy and therefore support only the LTS versions. When an LTS version goes out of support, we will update the major version of the library, drop support for the previous LTS version, and only target the next LTS version.
Standards.AspNetCore is available as a NuGet package.
Useful for ensuring consistent Date format contracts in RESTful APIs. IsoDateModelBinder
enforces DateTime
model binding with ISO-8601 format (YYYY-MM-DD) in MVC. This can be used in two ways:
- In single Controller actions:
[HttpGet]
public IActionResult Get([ModelBinder(typeof(IsoDateModelBinder))] DateTime date) {
return Ok("Date is in ISO format");
}
- Set globally in the application via Startup:
public override void ConfigureServices(IServiceCollection services) {
services.AddControllers(options => {
options.ModelBinderProviders.Insert(0, new IsoDateModelBinderProvider());
})
}
Then, only dates in ISO-8601 format (YYYY-MM-DD) can be binded. For example, /api?date=2021-01-01
will be successfully binded. However, /api?date=01-01-2021
will not, and the following error message will be added to the problem details response:
"Invalid date; must be in ISO-8601 format i.e. YYYY-MM-DD."
Currently only IsoDateModelBinder
is implemented. The intention is for further useful international standards to be implemented in this library.
Check out the contributing page to see the best ways to contribute.
See the Code of Conduct for the best ways to interact with this project.
Standards.AspNetCore is licensed under the MIT license.