OptionsBuilderDataAnnotationsExtensions.ValidateDataAnnotations<TOptions> Method
Definition
Important
Some information relates to prerelease product that may be substantially modified before it’s released. Microsoft makes no warranties, express or implied, with respect to the information provided here.
Registers this options instance for validation of its DataAnnotations.
public:
generic <typename TOptions>
where TOptions : class[System::Runtime::CompilerServices::Extension]
static Microsoft::Extensions::Options::OptionsBuilder<TOptions> ^ ValidateDataAnnotations(Microsoft::Extensions::Options::OptionsBuilder<TOptions> ^ optionsBuilder);
[System.Diagnostics.CodeAnalysis.RequiresUnreferencedCode("Uses DataAnnotationValidateOptions which is unsafe given that the options type passed in when calling Validate cannot be statically analyzed so its members may be trimmed.")]
public static Microsoft.Extensions.Options.OptionsBuilder<TOptions> ValidateDataAnnotations<TOptions>(this Microsoft.Extensions.Options.OptionsBuilder<TOptions> optionsBuilder) where TOptions : class;
public static Microsoft.Extensions.Options.OptionsBuilder<TOptions> ValidateDataAnnotations<TOptions>(this Microsoft.Extensions.Options.OptionsBuilder<TOptions> optionsBuilder) where TOptions : class;
[<System.Diagnostics.CodeAnalysis.RequiresUnreferencedCode("Uses DataAnnotationValidateOptions which is unsafe given that the options type passed in when calling Validate cannot be statically analyzed so its members may be trimmed.")>]
static member ValidateDataAnnotations : Microsoft.Extensions.Options.OptionsBuilder<'Options (requires 'Options : null)> -> Microsoft.Extensions.Options.OptionsBuilder<'Options (requires 'Options : null)> (requires 'Options : null)
static member ValidateDataAnnotations : Microsoft.Extensions.Options.OptionsBuilder<'Options (requires 'Options : null)> -> Microsoft.Extensions.Options.OptionsBuilder<'Options (requires 'Options : null)> (requires 'Options : null)
<Extension()>
Public Function ValidateDataAnnotations(Of TOptions As Class) (optionsBuilder As OptionsBuilder(Of TOptions)) As OptionsBuilder(Of TOptions)
Type Parameters
- TOptions
The options type to be configured.
Parameters
- optionsBuilder
- OptionsBuilder<TOptions>
The options builder to add the services to.
Returns
The OptionsBuilder<TOptions> so that additional calls can be chained.
- Attributes
Remarks
Synchronous validation runs when an options instance is created. When targeting .NET 11 or later, asynchronous validation (including AsyncValidationAttribute-derived attributes) runs during startup when ValidateOnStart() is also called. If ValidateOnStart() is not called, attributes deriving from AsyncValidationAttribute are never evaluated asynchronously: runtime options access triggers only synchronous validation, which invokes the attribute's synchronous fallback instead. The built-in IOptionsSnapshot<TOptions> implementation always uses synchronous attribute validation and never calls the asynchronous IsValidAsync method. Options created before startup validation or recreated by the built-in IOptionsMonitor<TOptions> implementation after a change also use synchronous validation. To support these paths, ensure an AsyncValidationAttribute-derived attribute provides a synchronous IsValid fallback that does not throw.