Class ConfigureOptionsExtensions
- Namespace
- Excalibur.Dispatch.Extensions
- Assembly
- Excalibur.Dispatch.dll
Provides extension methods for configuring options with defaults and custom configuration.
public static class ConfigureOptionsExtensions
- Inheritance
-
ConfigureOptionsExtensions
- Inherited Members
Remarks
Every method here composes ordinary OptionsServiceCollectionExtensions configuration callbacks, so the options instance is populated by direct property assignment at resolution time. No reflection, expression compilation or serialization is involved, which keeps these helpers usable under trimming and ahead-of-time compilation.
Methods
ConfigureNamedOptions<T>(IServiceCollection, string, Action<T>?, Action<T>)
Configures named options with defaults and custom configuration.
public static IServiceCollection ConfigureNamedOptions<T>(this IServiceCollection services, string name, Action<T>? configure, Action<T> defaults) where T : class, new()
Parameters
servicesIServiceCollectionThe service collection.
namestringThe name of the options instance.
configureAction<T>Optional custom configuration action.
defaultsAction<T>Required defaults configuration action.
Returns
- IServiceCollection
The service collection for chaining.
Type Parameters
TThe options type to configure.
ConfigureOptionsWithDeepClone<T>(IServiceCollection, Action<T>?, Action<T>)
Configures options such that no state is shared between resolved options instances.
public static IServiceCollection ConfigureOptionsWithDeepClone<T>(this IServiceCollection services, Action<T>? configure, Action<T> defaults) where T : class, new()
Parameters
servicesIServiceCollectionThe service collection.
configureAction<T>Optional custom configuration action.
defaultsAction<T>Required defaults configuration action.
Returns
- IServiceCollection
The service collection for chaining.
Type Parameters
TThe options type to configure.
Remarks
Both actions run against each options instance as it is created, so any nested object they allocate belongs to that instance alone. There is no shared template to clone, which is why this behaves identically to ConfigureOptions<T>(IServiceCollection, Action<T>?, Action<T>).
ConfigureOptionsWithValidation<T>(IServiceCollection, Action<T>?, Action<T>, Func<T, string?>)
Configures options with defaults, custom configuration, and validation.
public static IServiceCollection ConfigureOptionsWithValidation<T>(this IServiceCollection services, Action<T>? configure, Action<T> defaults, Func<T, string?> validate) where T : class, new()
Parameters
servicesIServiceCollectionThe service collection.
configureAction<T>Optional custom configuration action.
defaultsAction<T>Required defaults configuration action.
validateFunc<T, string>Validation function that returns validation errors or null if valid.
Returns
- IServiceCollection
The service collection for chaining.
Type Parameters
TThe options type to configure.
ConfigureOptions<T>(IServiceCollection, Action<T>?, Action<T>)
Configures options of type T with defaults and optional custom configuration.
public static IServiceCollection ConfigureOptions<T>(this IServiceCollection services, Action<T>? configure, Action<T> defaults) where T : class, new()
Parameters
servicesIServiceCollectionThe service collection.
configureAction<T>Optional custom configuration action.
defaultsAction<T>Required defaults configuration action.
Returns
- IServiceCollection
The service collection for chaining.
Type Parameters
TThe options type to configure.
Remarks
The defaults action runs before the custom configuration action, so custom configuration wins on any property both of them set. Properties neither action touches keep whatever the options instance already carries.
Exceptions
- ArgumentNullException
Thrown when
servicesordefaultsis null.