-
Notifications
You must be signed in to change notification settings - Fork 4.5k
/
ConfigureFromConfigurationOptions.cs
33 lines (30 loc) · 1.65 KB
/
ConfigureFromConfigurationOptions.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
using System;
using System.Diagnostics.CodeAnalysis;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
namespace Microsoft.Extensions.Options
{
// REVIEW: consider deleting/obsoleting, not used by Configure anymore (in favor of name), left for breaking change)
/// <summary>
/// Configures an option instance by using <see cref="ConfigurationBinder.Bind(IConfiguration, object)"/> against an <see cref="IConfiguration"/>.
/// </summary>
/// <typeparam name="TOptions">The type of options to bind.</typeparam>
public class ConfigureFromConfigurationOptions<[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.All)] TOptions> : ConfigureOptions<TOptions>
where TOptions : class
{
/// <summary>
/// Constructor that takes the <see cref="IConfiguration"/> instance to bind against.
/// </summary>
/// <param name="config">The <see cref="IConfiguration"/> instance.</param>
//Even though TOptions is annotated, we need to annotate as RUC as we can't guarantee properties on referenced types are preserved.
[RequiresDynamicCode(OptionsBuilderConfigurationExtensions.RequiresDynamicCodeMessage)]
[RequiresUnreferencedCode(OptionsBuilderConfigurationExtensions.TrimmingRequiredUnreferencedCodeMessage)]
public ConfigureFromConfigurationOptions(IConfiguration config)
: base(options => ConfigurationBinder.Bind(config, options))
{
ThrowHelper.ThrowIfNull(config);
}
}
}