DataAnnotationValidateOptions<TOptions>.ValidateAsync 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.
Asynchronously validates a specific named options instance (or all when name is null).
public System.Threading.Tasks.Task<Microsoft.Extensions.Options.ValidateOptionsResult> ValidateAsync(string? name, TOptions options, System.Threading.CancellationToken cancellationToken = default);
abstract member ValidateAsync : string * 'Options * System.Threading.CancellationToken -> System.Threading.Tasks.Task<Microsoft.Extensions.Options.ValidateOptionsResult>
override this.ValidateAsync : string * 'Options * System.Threading.CancellationToken -> System.Threading.Tasks.Task<Microsoft.Extensions.Options.ValidateOptionsResult>
Public Function ValidateAsync (name As String, options As TOptions, Optional cancellationToken As CancellationToken = Nothing) As Task(Of ValidateOptionsResult)
Parameters
- name
- String
The name of the options instance being validated.
- options
- TOptions
The options instance.
- cancellationToken
- CancellationToken
The token to monitor for cancellation requests.
Returns
The ValidateOptionsResult result.
Implements
Remarks
The built-in asynchronous options path invokes this method instead of Validate(String, TOptions). This method performs complete DataAnnotations validation, including synchronous and asynchronous attributes, and recursively validates members marked with ValidateObjectMembersAttribute or ValidateEnumeratedItemsAttribute. The cancellationToken is propagated from Host.StartAsync(CancellationToken). By default, no startup timeout is applied. Configure HostOptions.StartupTimeout or pass a CancellationToken with a timeout to Host.StartAsync to bound I/O-bound async validators:
builder.Services.Configure<HostOptions>(opts =>
opts.StartupTimeout = TimeSpan.FromSeconds(30));
Cancellation is cooperative. Validation cleanup awaits started work, so a validator that ignores the token can delay completion. A timeout-linked token requests cancellation; it does not enforce a hard completion deadline.