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))); }
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 override object CreateClient(Type clientType, IConfiguration configuration, TokenCredential credential, object clientOptions) { if (clientType == null) { throw new ArgumentNullException(nameof(clientType)); } if (configuration == null) { throw new ArgumentNullException(nameof(configuration)); } if (clientOptions == null) { throw new ArgumentNullException(nameof(clientOptions)); } return(ClientFactory.CreateClient(clientType, clientOptions.GetType(), clientOptions, configuration, credential)); }
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))); }