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 die Optionsinstanz erstellt oder darauf zugegriffen wird. Bei der Zielbestimmung .NET 11 oder höher wird die asynchrone Überprüfung (einschließlich AsyncValidationAttributeabgeleiteter Attribute) beim Start einmal ausgeführt und nur, 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. Stellen Sie bei Verwendung AsyncValidationAttributevon von -abgeleiteten Attributen sicher, dass der synchrone Fallback nicht ausgelöst wird: Die synchrone IsValid Überprüfung wird immer noch für jeden Optionszugriff ausgeführt, sodass eine ausgelöste Fallbackoberfläche als Ausnahme für jeden Zugriff (z. B. beim Auflösen IOptions{TOptions}.Value) ausgeführt wird, auch wenn die Startüberprüfung erfolgreich war.

Gilt für: