public static OptionsBuilder <TOption> AutoBind <TOption>(this OptionsBuilder <TOption> builder) where TOption : class { if (Configuration == null) { var provider = builder.Services.BuildServiceProvider(); Configuration = provider.GetService <IConfiguration>(); } builder.Bind(Configuration.GetSection(new SectionNameResolver <TOption>().Resolve())); return(builder); }
/// <summary> /// Registers a configuration instance which <typeparamref name="TOptions"/> will bind against. /// </summary> /// <typeparam name="TOptions">The options type to be configured.</typeparam> /// <param name="optionsBuilder">The options builder to add the services to.</param> /// <param name="config">The configuration being bound.</param> /// <returns>The <see cref="OptionsBuilder{TOptions}"/> so that additional calls can be chained.</returns> public static OptionsBuilder <TOptions> Bind <TOptions>(this OptionsBuilder <TOptions> optionsBuilder, IConfiguration config) where TOptions : class => optionsBuilder.Bind(config, _ => { });
public static OptionsBuilder <TOptions> Bind <[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.All)] TOptions>(this OptionsBuilder <TOptions> optionsBuilder, IConfiguration config) where TOptions : class => optionsBuilder.Bind(config, _ => { });
/// <summary> /// From <see cref="IConfiguration"/> binding /// </summary> /// <typeparam name="TOptions"></typeparam> /// <param name="optionsBuilder"></param> /// <returns></returns> public static OptionsBuilder <TOptions> Bind <TOptions>(this OptionsBuilder <TOptions> optionsBuilder) where TOptions : class { return(optionsBuilder.Bind(Options.Options.DefaultName)); }