Table of Contents

AddConfiguredOptions Method

Definition

Namespace
Cuemon.Extensions.DependencyInjection
Assemblies
Cuemon.Extensions.DependencyInjection.dll
Source
src/Cuemon.Extensions.DependencyInjection/ServiceCollectionExtensions.cs

AddConfiguredOptions<TOptions>(IServiceCollection, Action<TOptions>)

Registers the specified setup with the Microsoft Options pattern and enables direct consumption of TOptions and Action<T>.

public static IServiceCollection AddConfiguredOptions<TOptions>(this IServiceCollection services, Action<TOptions> setup) where TOptions : class, IParameterObject, new()

Parameters

services IServiceCollection

The IServiceCollection to extend.

setup Action<TOptions>

The delegate that configures the public read-write properties of TOptions.

Returns

IServiceCollection

A reference to services so that additional configuration calls can be chained.

Type Parameters

TOptions

The options type to be configured.

Remarks

Microsoft Options constructs and configures the options when they are materialized. The IPostConfigurableParameterObject and IValidatableParameterObject conventions participate in its post-configuration and validation stages for all options names. Recoverable validation exceptions become OptionsValidationException failures; post-configuration exceptions and fatal validation exceptions propagate without translation.

Post-configurators and validators execute in registration order within their respective stages. Cuemon conventions are not forced to run last.

Direct TOptions consumption is registered as a singleton resolving the default Value. The normal lifecycles of IOptionsSnapshot<TOptions> and IOptionsMonitor<TOptions> are preserved.

The first call for an options type registers the exact setup instance as Action<T> and as the primary default options configurator. Subsequent calls for that type are ignored. Additional Microsoft Configure registrations still compose in registration order, but are not included in the injectable delegate. Invoking the delegate directly only applies its configuration; it does not perform post-configuration or validation.

Exceptions

ArgumentNullException

services cannot be null.

  • or - setup cannot be null.