Skip to content

marcusturewicz/standards-aspnetcore

Repository files navigation

Standards.AspNetCore logo

Library of standards implemented to use in ASP.NET Core.

CI/CD Nuget Nuget

For example, it provides convenient abstractions for enforcing DateTime objects are binded with ISO-8601 format (YYYY-MM-DD) in MVC.

Compatibility

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.

Getting Started

Standards.AspNetCore is available as a NuGet package.

Features

IsoDateModelBinder and IsoDateModelBinderProvider

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:

  1. In single Controller actions:
[HttpGet]
public IActionResult Get([ModelBinder(typeof(IsoDateModelBinder))] DateTime date) {
    return Ok("Date is in ISO format");
}
  1. 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."

Roadmap

Currently only IsoDateModelBinder is implemented. The intention is for further useful international standards to be implemented in this library.

Contributing

Check out the contributing page to see the best ways to contribute.

Code of conduct

See the Code of Conduct for the best ways to interact with this project.

License

Standards.AspNetCore is licensed under the MIT license.

About

Library of standards implemented to use in ASP.NET Core

Resources

License

Code of conduct

Stars

Watchers

Forks

Languages