Ejemplo n.º 1
0
 /// <summary>
 ///     Registers a configuration options source factory which <typeparamref name="TOptions"/> will bind against.
 /// </summary>
 public OptionsBuilder <TOptions> Bind(IConfigureOptionsSource <TOptions> source)
 {
     Services
     .AddSingleton <IOptionsChangeTokenSource <TOptions> >(_ => new LambdaOptionsChangeTokenSource <TOptions>(
                                                               Name,
                                                               source.GetChangeToken))
     .AddSingleton <IConfigureOptions <TOptions> >(_ => new ConfigureNamedOptions <TOptions>(
                                                       Name,
                                                       source.Configure));
     return(this);
 }
Ejemplo n.º 2
0
 /// <summary>
 ///     Registers an options source instance which TOptions will bind against.
 /// </summary>
 /// <param name="services">The <see cref="IServiceCollection"/> to add the services to.</param>
 /// <param name="name">The name of the options instance.</param>
 /// <param name="source">The options source being bound.</param>
 public static IServiceCollection Configure <TOptions>(this IServiceCollection services, string name, IConfigureOptionsSource <TOptions> source)
     where TOptions : class => services
 .AddOptions <TOptions>(name)
 .Bind(source)
 .ValidateDataAnnotations()
 .Services;