Sprache

OptionsBuilderDataAnnotationsExtensions.ValidateDataAnnotations<TOptions> Methode

Definition

Registriert diese Optionsinstanz für die Überprüfung ihrer 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)

Typparameter

TOptions

Der zu konfigurierende Optionstyp.

Parameter

optionsBuilder
OptionsBuilder<TOptions>

Der Options-Generator, dem die Dienste hinzugefügt werden sollen.

Gibt zurück

Dadurch OptionsBuilder<TOptions> können zusätzliche Aufrufe verkettet werden.

Attribute

Hinweise

Die synchrone Überprüfung wird ausgeführt, wenn eine Optionsinstanz erstellt wird. Bei der Zielbestimmung .NET 11 oder höher wird die asynchrone Überprüfung (einschließlich AsyncValidationAttributeabgeleiteter Attribute) während des Starts ausgeführt, wenn ValidateOnStart() sie auch aufgerufen wird. Wenn ValidateOnStart() nicht aufgerufen wird, werden Attribute, die von AsyncValidationAttribute der Ableitung abgeleitet werden, niemals asynchron ausgewertet: Der Laufzeitoptionenzugriff löst nur die synchrone Überprüfung aus, wodurch stattdessen das synchrone Fallback des Attributs aufgerufen wird. Die integrierte IOptionsSnapshot<TOptions> Implementierung verwendet immer die synchrone Attributüberprüfung und ruft niemals die asynchrone IsValidAsync Methode auf. Optionen, die vor der Startüberprüfung erstellt oder von der integrierten IOptionsMonitor<TOptions> Implementierung nach einer Änderung neu erstellt wurden, verwenden auch die synchrone Überprüfung. Wenn eine erforderliche Regel gilt, aber nicht synchron ausgewertet werden kann, sollte die synchrone IsValid Implementierung des Attributs ausgelöst InvalidOperationException werden, um zu melden, dass der Aufruf nicht unterstützt wird, anstatt erfolglos zurückzugeben.

Gilt für: