System.ClientModel.ConfigurationExtensions
Static class containing extension methods for IConfiguration to get ClientSettings.
public static IClientBuilder AddClient<TClient, TSettings>(this IHostApplicationBuilder host, string sectionName) where TSettings : ClientSettings
Adds a singleton client of the specified type to the IHostApplicationBuilder's service collection.
public static IClientBuilder AddClient<TClient, TSettings>(this IHostApplicationBuilder host, string sectionName, Action<TSettings> configureSettings) where TSettings : ClientSettings
Adds a singleton client of the specified type to the IHostApplicationBuilder's service collection.
public static IServiceCollection AddCredentialResolver<T>(this IServiceCollection services) where T : CredentialResolver
Registers T as a CredentialResolver
service. Idempotent by implementation type — calling twice with the
same T registers a single instance.
public static IHostApplicationBuilder AddCredentialResolver<T>(this IHostApplicationBuilder builder) where T : CredentialResolver
Registers T as a CredentialResolver
service on the host's service collection.
public static IClientBuilder AddKeyedClient<TClient, TSettings>(this IHostApplicationBuilder host, string key, string sectionName) where TSettings : ClientSettings
Adds a keyed singleton client of the specified type to the IHostApplicationBuilder's service collection.
public static IClientBuilder AddKeyedClient<TClient, TSettings>(this IHostApplicationBuilder host, string key, string sectionName, Action<TSettings> configureSettings) where TSettings : ClientSettings
Adds a keyed singleton client of the specified type to the IHostApplicationBuilder's service collection.
public static T GetClientSettings<T>(this IConfiguration configuration, string sectionName) where T : ClientSettings
Creates an instance of T and sets its properties from the specified IConfiguration.
public static T GetClientSettings<T>(this IConfiguration configuration, string sectionName, CredentialResolver[] resolvers) where T : ClientSettings
Creates an instance of T and sets its properties
from the specified IConfiguration, additionally
resolving CredentialProvider from the
supplied CredentialResolver chain.
public static T GetClientSettings<T>(this IConfiguration configuration, string sectionName, IEnumerable<CredentialResolver> resolvers, Action<IConfigurationSection> configureOverrides) where T : ClientSettings
Creates an instance of T and sets its properties
from the specified IConfiguration, additionally
resolving CredentialProvider from the
supplied CredentialResolver chain after applying
configureOverrides to the credential section.
public static CredentialSettings GetCredentialSettings(this IConfiguration configuration, string sectionName)
Returns a CredentialSettings bound from the named
credential section. The supplied sectionName is
treated as the credential section itself (not a parent client
section). The returned settings expose the inline
Key (for ApiKey sections) and the
resolver-supplied TokenProvider
(for token sections, when a resolver matches), so standalone callers
can dispatch on either without binding a ClientSettings.
Returns null only when the named section does not
exist; when the section exists but no resolver claims it, returns a
populated CredentialSettings with
TokenProvider set to
null. Never throws.
public static CredentialSettings GetCredentialSettings(this IConfiguration configuration, string sectionName, CredentialResolver[] resolvers)
Walks the supplied CredentialResolver chain in order
(first match wins) against the named credential section and returns
a CredentialSettings populated with both the bound
metadata (Key, CredentialSource,
AdditionalProperties) and the resolver-supplied
TokenProvider. The supplied
sectionName is treated as the credential section
itself. Returns null only when the named section
does not exist; when the section exists but no resolver claims it,
returns settings with TokenProvider
set to null. Never throws.
public static CredentialSettings GetCredentialSettings(this IConfiguration configuration, string sectionName, IEnumerable<CredentialResolver> resolvers, Action<IConfigurationSection> configureOverrides)
Applies configureOverrides to a writable overlay of
the named credential section, then walks the supplied
CredentialResolver chain to populate
TokenProvider. Unlike
GetClientSettings<T>
— which binds the surrounding ClientSettings from the original
(non-overlaid) configuration and only feeds the overlay to the
resolver chain — the returned CredentialSettings here
reflects the post-overlay merged view for Key,
CredentialSource, AdditionalProperties, and the
Item indexer. The supplied
sectionName is treated as the credential section
itself. Returns null only when the original section
does not exist; overrides cannot synthesize a credential into a
missing section. Never throws.