Microsoft.Extensions.Options.DataAnnotations 9.0.1
About
Microsoft.Extensions.Options.DataAnnotations is a library that adds extra validation functionality to configuration options using data annotations.
It allows to apply validation rules to configuration classes to ensure they are correctly configured before the application starts running.
This way, misconfiguration issues are catched early during the application startup rather than facing them later in production.
Key Features
- Enables validation of configuration options using data annotations.
- Early detection of misconfiguration issues during application startup.
How to Use
While configuring services, chain the ValidateDataAnnotations() and ValidateOnStart() methods to the AddOptions method for your configuration class.
Here is a simple example demonstrating how to validate options on application startup:
services
.AddOptions<MyOptions>()
.ValidateDataAnnotations()
.ValidateOnStart();
In the configuration class, use data annotations to specify the validation rules.
For instance, in the following MyOptions class, the Name property is marked as required:
using System.ComponentModel.DataAnnotations;
public class MyOptions
{
[Required(AllowEmptyStrings = false)]
public string Name { get; set; }
}
With this setup, an error indicating that the Name field is required will be thrown upon startup if it hasn't been configured.
Main Types
The main types provided by this library are:
Microsoft.Extensions.Options.DataAnnotationsValidateOptions<TOptions>Microsoft.Extensions.DependencyInjection.OptionsBuilderDataAnnotationsExtensions
Additional Documentation
Related Packages
Core options: Microsoft.Extensions.Options
Feedback & Contributing
Microsoft.Extensions.Options.DataAnnotations is released as open source under the MIT license. Bug reports and contributions are welcome at the GitHub repository.
Showing the top 20 packages that depend on Microsoft.Extensions.Options.DataAnnotations.
| Packages | Downloads |
|---|---|
|
Umbraco.Cms.Core
Contains the core assembly needed to run Umbraco CMS.
|
15 |
|
Umbraco.Cms.Core
Contains the core assembly needed to run Umbraco CMS.
|
13 |
|
Umbraco.Cms.Persistence.EFCore.SqlServer
Adds support for Entity Framework Core SQL Server migrations to Umbraco CMS.
|
13 |
|
Umbraco.Cms.Persistence.SqlServer
Adds support for SQL Server to Umbraco CMS.
|
13 |
|
Umbraco.Cms.Core
Contains the core assembly needed to run Umbraco Cms. This package only contains the assembly, and can be used for package development. Use the template in the Umbraco.Templates package to setup Umbraco
|
12 |
|
Umbraco.Cms.Core
Contains the core assembly needed to run Umbraco CMS.
|
12 |
|
Umbraco.Cms.PublishedCache.NuCache
Contains the published cache assembly needed to run Umbraco CMS.
|
12 |
|
Umbraco.Cms.Core
Contains the core assembly needed to run Umbraco CMS.
|
10 |
.NET Framework 4.6.2
- Microsoft.Extensions.DependencyInjection.Abstractions (>= 9.0.1)
- Microsoft.Extensions.Options (>= 9.0.1)
.NET Standard 2.1
- System.ComponentModel.Annotations (>= 5.0.0)
- Microsoft.Extensions.Options (>= 9.0.1)
- Microsoft.Extensions.DependencyInjection.Abstractions (>= 9.0.1)
.NET Standard 2.0
- Microsoft.Extensions.Options (>= 9.0.1)
- Microsoft.Extensions.DependencyInjection.Abstractions (>= 9.0.1)
- System.ComponentModel.Annotations (>= 5.0.0)
.NET 9.0
- Microsoft.Extensions.DependencyInjection.Abstractions (>= 9.0.1)
- Microsoft.Extensions.Options (>= 9.0.1)
.NET 8.0
- Microsoft.Extensions.Options (>= 9.0.1)
- Microsoft.Extensions.DependencyInjection.Abstractions (>= 9.0.1)
| Version | Downloads | Last updated |
|---|---|---|
| 9.0.2 | 16 | 02/18/2025 |
| 9.0.1 | 12 | 02/18/2025 |
| 9.0.0 | 14 | 02/18/2025 |
| 8.0.0 | 16 | 02/22/2024 |
| 7.0.0 | 17 | 06/17/2023 |
| 7.0.0-rc.2.22472.3 | 13 | 02/18/2025 |
| 6.0.1 | 14 | 02/18/2025 |
| 6.0.0 | 15 | 06/17/2023 |
| 5.0.0 | 14 | 07/12/2023 |
| 5.0.0-rc.2.20475.5 | 14 | 02/18/2025 |
| 3.1.32 | 13 | 02/18/2025 |
| 3.1.31 | 13 | 02/18/2025 |
| 3.1.30 | 14 | 02/18/2025 |
| 3.1.29 | 14 | 02/18/2025 |
| 3.1.28 | 14 | 02/18/2025 |
| 3.1.27 | 14 | 02/18/2025 |
| 3.1.26 | 14 | 02/18/2025 |
| 3.1.25 | 14 | 02/18/2025 |
| 3.1.24 | 14 | 02/18/2025 |
| 3.1.23 | 14 | 02/18/2025 |
| 3.1.22 | 14 | 02/18/2025 |
| 3.1.21 | 13 | 02/18/2025 |
| 3.1.20 | 13 | 02/18/2025 |
| 3.1.19 | 12 | 02/18/2025 |
| 3.1.18 | 14 | 02/18/2025 |
| 3.1.17 | 13 | 02/18/2025 |
| 3.1.16 | 13 | 02/18/2025 |
| 3.1.15 | 14 | 02/18/2025 |
| 3.1.14 | 14 | 02/18/2025 |
| 3.1.13 | 14 | 02/18/2025 |
| 3.1.12 | 14 | 02/18/2025 |
| 3.1.11 | 13 | 02/18/2025 |
| 3.1.10 | 13 | 02/18/2025 |
| 3.1.9 | 15 | 02/18/2025 |
| 3.1.8 | 14 | 02/18/2025 |
| 3.1.7 | 14 | 02/18/2025 |
| 3.1.6 | 15 | 02/18/2025 |
| 3.1.5 | 14 | 02/18/2025 |
| 3.1.4 | 15 | 02/18/2025 |
| 3.1.3 | 13 | 02/18/2025 |
| 3.1.2 | 13 | 02/18/2025 |
| 3.1.1 | 14 | 02/18/2025 |
| 3.1.0 | 14 | 02/18/2025 |
| 3.0.3 | 14 | 02/18/2025 |
| 3.0.2 | 14 | 02/18/2025 |
| 3.0.1 | 14 | 02/18/2025 |
| 3.0.0 | 14 | 02/18/2025 |
| 2.2.0 | 14 | 02/18/2025 |