OptionsBuilderExtensions.AddValidatedOptions Method

Definition

Overloads

AddValidatedOptions<TOptions,TValidateOptions>(IServiceCollection, String)

Adds named options that are automatically validated during startup using a custom validator.

AddValidatedOptions<TOptions>(IServiceCollection, String)

Adds named options that are automatically validated during startup using a built-in validator.

AddValidatedOptions<TOptions,TValidateOptions>(IServiceCollection, String)

Adds named options that are automatically validated during startup using a custom validator.

C#
public static Microsoft.Extensions.Options.OptionsBuilder<TOptions> AddValidatedOptions<TOptions,TValidateOptions>(this Microsoft.Extensions.DependencyInjection.IServiceCollection services, string? name = default) where TOptions : class where TValidateOptions : class, Microsoft.Extensions.Options.IValidateOptions<TOptions>;

Type Parameters

TOptions

Options to validate.

TValidateOptions

Validator to use.

Parameters

services
IServiceCollection

Service collection.

name
String

Name of the options.

Returns

The OptionsBuilder<TOptions> so that additional calls can be chained.

Applies to

.NET 10 (package-provided) an aner Versiounen
Produkt Versiounen
.NET 8 (package-provided), 9 (package-provided), 10 (package-provided)

AddValidatedOptions<TOptions>(IServiceCollection, String)

Adds named options that are automatically validated during startup using a built-in validator.

C#
public static Microsoft.Extensions.Options.OptionsBuilder<TOptions> AddValidatedOptions<TOptions>(this Microsoft.Extensions.DependencyInjection.IServiceCollection services, string? name = default) where TOptions : class;

Type Parameters

TOptions

Options to validate.

Parameters

services
IServiceCollection

Service collection.

name
String

Name of the options.

Returns

The OptionsBuilder<TOptions> so that additional calls can be chained.

Remarks

We recommend using custom generated validator.

Applies to

.NET 10 (package-provided) an aner Versiounen
Produkt Versiounen
.NET 8 (package-provided), 9 (package-provided), 10 (package-provided)