DovetailConfigurationOptionsExtensions Methods
Extensions.Options pipeline. AddDovetailConfigurationOptions(IServiceCollection, string, Func<IConfiguration, TOptions>) Section titled AddDovetailConfigurationOptions(IServiceCollection, string, Func<IConfiguration, TOptions>)extensionOptionsBuilder<TOptions> TOptions from the configuration section at sectionPath with create, without reflection. public static class DovetailConfigurationOptionsExtensions{ public static OptionsBuilder<TOptions> AddDovetailConfigurationOptions<TOptions>( this IServiceCollection services, string sectionPath, Func<IConfiguration, TOptions> create) { // ... }}Parameters
servicesIServiceCollection The service collection to register against.sectionPath stringThe path of the configuration section to create from, such as Server or Http:Retry .createFunc<IConfiguration, TOptions> Creates an instance from a configuration section.Returns
OptionsBuilder<TOptions> The Options.OptionsBuilder`1 for the default name, for further configuration such as Validate and ValidateOnStart() . Exceptions
ArgumentNullExceptionservices, sectionPath , or create is null.ArgumentExceptionsectionPath is empty.Remarks
This is the one registration the generated configuration joint emits, for every [Dovetail type. It registers an Options. that creates each instance with create, unless a factory is already registered for T. That is a Try, so an Options. the application registered itself wins over this one, and create is never called for that type. Registered before this call, the application's factory makes this registration a no-op. Registered after it with a plain Add, it is the last registration, which the container resolves. The factory derives from Options., so configure and post-configure actions and validators still run on the instance create returns.
A type is created from one section only. When several calls register a section for the same type, the first one wins and the rest are ignored, as with any other Try registration.
The configuration is the application's Configuration., which the service provider supplies when the options are first created. create is called with the section at section. A change token source watches that configuration, so Options. and Options. observe reloads. Dovetail only registers the default options: asking for any other options name throws Invalid.
On .NET 11, don't give a type registered this way asynchronous validators: the options pipeline only runs them through the built-in Options. itself, and through a derived factory they fail synchronous validation.