public TClient CreateClient(string name) { _logForwarder.Start(); var globalOptions = _globalOptions.CurrentValue; FallbackClientRegistration <TClient> registration; lock (_clientRegistrations) { if (!_clientRegistrations.TryGetValue(name, out registration)) { var section = globalOptions.ConfigurationRootResolver?.Invoke(_serviceProvider).GetSection(name); if (!section.Exists()) { throw new InvalidOperationException($"Unable to find a configuration section with the name {name} to configure the client with or the configuration root wasn't set."); } registration = new FallbackClientRegistration <TClient>( name, (options, credential) => (TClient)ClientFactory.CreateClient(typeof(TClient), _clientOptionType, options, section, credential), section); _clientRegistrations.Add(name, registration); } } return(registration.GetClient( GetClientOptions(globalOptions, registration.Configuration), ClientFactory.CreateCredential(registration.Configuration) ?? globalOptions.CredentialFactory(_serviceProvider))); }
/// <summary> /// Adds a configuration instance to initialize all clients from. /// </summary> /// <param name="configuration">The configuration instance.</param> /// <returns>This instance.</returns> public AzureClientFactoryBuilder ConfigureDefaults(IConfiguration configuration) { ConfigureDefaults(options => configuration.Bind(options)); var credentialsFromConfig = ClientFactory.CreateCredential(configuration); if (credentialsFromConfig != null) { UseCredential(credentialsFromConfig); } return(this); }
IAzureClientBuilder <TClient, TOptions> IAzureClientFactoryBuilderWithConfiguration <IConfiguration> .RegisterClientFactory <TClient, TOptions>(IConfiguration configuration) { var credentialsFromConfig = ClientFactory.CreateCredential(configuration); var clientBuilder = ((IAzureClientFactoryBuilderWithCredential)this).RegisterClientFactory <TClient, TOptions>( (options, credentials) => (TClient)ClientFactory.CreateClient(typeof(TClient), typeof(TOptions), options, configuration, credentials)) .ConfigureOptions(configuration); if (credentialsFromConfig != null) { clientBuilder.WithCredential(credentialsFromConfig); } return(clientBuilder); }
public TClient CreateClient(string name) { if (_configurationRoot == null) { throw new InvalidOperationException($"Unable to find client registration with type '{typeof(TClient).Name}' and name '{name}'."); } _logForwarder.Start(); FallbackClientRegistration <TClient> registration; lock (_clientRegistrations) { if (!_clientRegistrations.TryGetValue(name, out registration)) { var section = _configurationRoot.GetSection(name); if (!section.Exists()) { throw new InvalidOperationException($"Unable to find a configuration section with the name {name} to configure the client with."); } registration = new FallbackClientRegistration <TClient>( name, (options, credential) => (TClient)ClientFactory.CreateClient(typeof(TClient), _clientOptionType, options, section, credential), section); _clientRegistrations.Add(name, registration); } } var currentOptions = _optionsFactory.CreateOptions(name); registration.Configuration.Bind(currentOptions); return(registration.GetClient(currentOptions, ClientFactory.CreateCredential(registration.Configuration) ?? _globalOptions.CredentialFactory(_serviceProvider))); }
/// <inheritdoc /> public override TokenCredential CreateCredential(IConfiguration configuration) { return(ClientFactory.CreateCredential(configuration) ?? _globalOptions.CurrentValue.CredentialFactory(_serviceProvider)); }