src/Kros.AspNetCore/Extensions/ServiceCollectionExtensions.cs
/// <summary>
/// Configure options of type <typeparamref name="TOptions"/> and binds it to section <paramref name="sectionName"/>
/// in <paramref name="configuration"/>.
/// </summary>
/// <typeparam name="TOptions">Type of the options.</typeparam>
/// <param name="services">Service collection where the options are registered.</param>
/// <param name="configuration">Configuration from which the options are loaded.</param>
/// <param name="sectionName">Section name in configuration.</param>
/// <returns>Returns input <paramref name="services"/>.</returns>
Configure options of type  and binds it to section
in .
Configure options of type and binds it to section in .
public static IServiceCollection ConfigureOptions<TOptions>(
            this IServiceCollection services,
            IConfiguration configuration,
            string sectionName) where TOptions : class, new()
        {
            services.Configure<TOptions>(options => configuration.GetSection(sectionName).Bind(options));
            services.AddTransient<TOptions>(ctx => ctx.GetRequiredService<IOptionsSnapshot<TOptions>>().Value);
            if (typeof(IValidatable).IsAssignableFrom(typeof(TOptions)))
            {
                services.AddSingleton<IValidatable>(ctx => (IValidatable)ctx.GetRequiredService<IOptions<TOptions>>().Value);
            }
            return services;
        }
public static IServiceCollection ConfigureOptions < TOptions > ( this IServiceCollection services , IConfiguration configuration , string sectionName ) where TOptions : class , new ( ) { services . Configure < TOptions > ( options => configuration . GetSection ( sectionName ) . Bind ( options ) ) ; services . AddTransient < TOptions > ( ctx => ctx . GetRequiredService < IOptionsSnapshot < TOptions > > ( ) . Value ) ; if ( typeof ( IValidatable ) . IsAssignableFrom ( typeof ( TOptions ) ) ) { services . AddSingleton < IValidatable > ( ctx => ( IValidatable ) ctx . GetRequiredService < IOptions < TOptions > > ( ) . Value ) ; } return services ; }
Configure options of type  and binds it to section
in .
Configure options of type and binds it to section in .
Returns input .
Returns input .
IServiceCollection
this
configuration
IConfiguration
Configuration from which the options are loaded.
Configuration from which the options are loaded .
sectionName
string
Section name in configuration.
Section name in configuration .
services
Service collection where the options are registered.
Service collection where the options are registered .
typeparam
Type of the options.
Type of the options .