4.10.0 (latest) 4.8.0 4.4.0 4.3.1 4.2.0 4.0.0 3.2.0

    public abstract class ClientBuilderBase<TClient>

Base class for API-specific builders.

## Inheritance

[object](https://learn.microsoft.com/dotnet/api/system.object) \> ClientBuilderBase\<TClient\>

## Inherited Members

[object.Equals(object)](https://learn.microsoft.com/dotnet/api/system.object.equals#system-object-equals(system-object)) [object.Equals(object, object)](https://learn.microsoft.com/dotnet/api/system.object.equals#system-object-equals(system-object-system-object)) [object.GetHashCode()](https://learn.microsoft.com/dotnet/api/system.object.gethashcode) [object.GetType()](https://learn.microsoft.com/dotnet/api/system.object.gettype) [object.MemberwiseClone()](https://learn.microsoft.com/dotnet/api/system.object.memberwiseclone) [object.ReferenceEquals(object, object)](https://learn.microsoft.com/dotnet/api/system.object.referenceequals) [object.ToString()](https://learn.microsoft.com/dotnet/api/system.object.tostring)

## Namespace

[Google.Api.Gax.Rest](https://docs.cloud.google.com/dotnet/docs/reference/Google.Api.Gax/latest/Google.Api.Gax.Rest.md.txt)

## Assembly

Google.Api.Gax.Rest.dll

| ## Type Parameter ||
|---|---|
| **Name** | **Description** |
| `TClient` | The type of client created by this builder. |

## Constructors

### ClientBuilderBase()

    protected ClientBuilderBase()

Creates a new instance with no settings.

## Properties

### ApiKey

    public string ApiKey { get; set; }

An API key to use instead of a regular credential. If this is non-null and no other credentials are supplied,
it will be used as the only credentials. If other credentials are supplied (such as through [CredentialsPath](https://docs.cloud.google.com/dotnet/docs/reference/Google.Api.Gax/latest/Google.Api.Gax.Rest.ClientBuilderBase-1.md.txt#Google_Api_Gax_Rest_ClientBuilderBase_1_CredentialsPath))
then the two values will both be used together.

| **Property Value** ||
|---|---|
| **Type** | **Description** |
| `string` |   |

### ApplicationName

    public string ApplicationName { get; set; }

A custom application name to use for this client, or null to use the default application name.

| **Property Value** ||
|---|---|
| **Type** | **Description** |
| `string` |   |

### BaseUri

    public string BaseUri { get; set; }

A custom base URI for the service, or null to use the default URI.

| **Property Value** ||
|---|---|
| **Type** | **Description** |
| `string` |   |

### Credential

    public ICredential Credential { get; set; }

The credential to use for authentication. This cannot be specified alongside other authentication properties.
Note that scopes are not automatically applied to this credential; if a scoped credential is required, the
scoping must be applied by the calling code.

| **Property Value** ||
|---|---|
| **Type** | **Description** |
| `ICredential` |   |

### CredentialsPath

    public string CredentialsPath { get; set; }

The path to the credentials file to use, or null if credentials are being provided in a different way.
The resulting credential is automatically scoped with the default scopes for the API.

| **Property Value** ||
|---|---|
| **Type** | **Description** |
| `string` |   |

**Remarks** Important: If you accept a credential configuration (credential JSON/File/Stream) from an external source
for authentication to Google Cloud, you must validate it before providing it to any Google API or library.
Providing an unvalidated credential configuration to Google APIs can compromise the security of your
systems and data. For more information, refer to
[Validate credential configurations from external sources](https://cloud.google.com/docs/authentication/external/externally-sourced-credentials).

### GoogleCredential

    public GoogleCredential GoogleCredential { get; set; }

The credentials to use as a [GoogleCredential](https://docs.cloud.google.com/dotnet/docs/reference/Google.Api.Gax/latest/Google.Api.Gax.Rest.ClientBuilderBase-1.md.txt#Google_Api_Gax_Rest_ClientBuilderBase_1_GoogleCredential), or null if credentials are being provided in
a different way. Note that unlike [Credential](https://docs.cloud.google.com/dotnet/docs/reference/Google.Api.Gax/latest/Google.Api.Gax.Rest.ClientBuilderBase-1.md.txt#Google_Api_Gax_Rest_ClientBuilderBase_1_Credential), settings for [QuotaProject](https://docs.cloud.google.com/dotnet/docs/reference/Google.Api.Gax/latest/Google.Api.Gax.Rest.ClientBuilderBase-1.md.txt#Google_Api_Gax_Rest_ClientBuilderBase_1_QuotaProject), and scopes
will be applied to this credential (creating a new one), in the same way as for
application default credentials and credentials specified using
[CredentialsPath](https://docs.cloud.google.com/dotnet/docs/reference/Google.Api.Gax/latest/Google.Api.Gax.Rest.ClientBuilderBase-1.md.txt#Google_Api_Gax_Rest_ClientBuilderBase_1_CredentialsPath) or [JsonCredentials](https://docs.cloud.google.com/dotnet/docs/reference/Google.Api.Gax/latest/Google.Api.Gax.Rest.ClientBuilderBase-1.md.txt#Google_Api_Gax_Rest_ClientBuilderBase_1_JsonCredentials).

| **Property Value** ||
|---|---|
| **Type** | **Description** |
| `GoogleCredential` |   |

### HttpClientFactory

    public IHttpClientFactory HttpClientFactory { get; set; }

An [IHttpClientFactory](https://github.com/googleapis/google-api-dotnet-client/blob/04e805147def8d2ec5b281c97ba77884dc123e0f/Src/Support/Google.Apis.Core/Http/IHttpClientFactory.cs) that will be used to obtain
[ConfigurableHttpClient](https://github.com/googleapis/google-api-dotnet-client/blob/04e805147def8d2ec5b281c97ba77884dc123e0f/Src/Support/Google.Apis.Core/Http/ConfigurableHttpClient.cs) for making API Http calls.
May be null, in which case an [HttpClientFactory](https://github.com/googleapis/google-api-dotnet-client/blob/04e805147def8d2ec5b281c97ba77884dc123e0f/Src/Support/Google.Apis.Core/Http/HttpClientFactory.cs)
will be used.

| **Property Value** ||
|---|---|
| **Type** | **Description** |
| `IHttpClientFactory` |   |

**Remarks** If you want to use custom HTTP clients, for instance, if you need to set a proxy,
you may do so by either

- Extending [HttpClientFactory](https://github.com/googleapis/google-api-dotnet-client/blob/04e805147def8d2ec5b281c97ba77884dc123e0f/Src/Support/Google.Apis.Core/Http/HttpClientFactory.cs). Refer to [HttpClientFactory](https://github.com/googleapis/google-api-dotnet-client/blob/04e805147def8d2ec5b281c97ba77884dc123e0f/Src/Support/Google.Apis.Core/Http/HttpClientFactory.cs) documentation for more information.
- On .NET Core 2.1 and above, using [HttpClientFromMessageHandlerFactory](https://github.com/googleapis/google-api-dotnet-client/blob/04e805147def8d2ec5b281c97ba77884dc123e0f/Src/Support/Google.Apis.Core/Http/HttpClientFromMessageHandlerFactory.cs) in combination with

  ```csharp
  System.Net.Http.IHttpClientFactory
  ```
  . Refer to [HttpClientFromMessageHandlerFactory](https://github.com/googleapis/google-api-dotnet-client/blob/04e805147def8d2ec5b281c97ba77884dc123e0f/Src/Support/Google.Apis.Core/Http/HttpClientFromMessageHandlerFactory.cs) documentation and <https://docs.microsoft.com/en-us/dotnet/architecture/microservices/implement-resilient-applications/use-httpclientfactory-to-implement-resilient-http-requests> for more information.

<br />

### JsonCredentials

    public string JsonCredentials { get; set; }

The credentials to use as a JSON string, or null if credentials are being provided in a different way.
The resulting credential is automatically scoped with the default scopes for the API.

| **Property Value** ||
|---|---|
| **Type** | **Description** |
| `string` |   |

**Remarks** Important: If you accept a credential configuration (credential JSON/File/Stream) from an external source
for authentication to Google Cloud, you must validate it before providing it to any Google API or library.
Providing an unvalidated credential configuration to Google APIs can compromise the security of your
systems and data. For more information, refer to
[Validate credential configurations from external sources](https://cloud.google.com/docs/authentication/external/externally-sourced-credentials).

### QuotaProject

    public string QuotaProject { get; set; }

The GCP project ID that should be used for quota and billing purposes.
May be null.

| **Property Value** ||
|---|---|
| **Type** | **Description** |
| `string` |   |

### UniverseDomain

    public string UniverseDomain { get; set; }

The universe domain to connect to, or null to use the default universe domain.

| **Property Value** ||
|---|---|
| **Type** | **Description** |
| `string` |   |

**Remarks**
[UniverseDomain](https://docs.cloud.google.com/dotnet/docs/reference/Google.Api.Gax/latest/Google.Api.Gax.Rest.ClientBuilderBase-1.md.txt#Google_Api_Gax_Rest_ClientBuilderBase_1_UniverseDomain) is used to build the base URI to connect to, unless [BaseUri](https://docs.cloud.google.com/dotnet/docs/reference/Google.Api.Gax/latest/Google.Api.Gax.Rest.ClientBuilderBase-1.md.txt#Google_Api_Gax_Rest_ClientBuilderBase_1_BaseUri)
is set, in which case [BaseUri](https://docs.cloud.google.com/dotnet/docs/reference/Google.Api.Gax/latest/Google.Api.Gax.Rest.ClientBuilderBase-1.md.txt#Google_Api_Gax_Rest_ClientBuilderBase_1_BaseUri) will be used without further modification.


If default credentials or one of [GoogleCredential](https://docs.cloud.google.com/dotnet/docs/reference/Google.Api.Gax/latest/Google.Api.Gax.Rest.ClientBuilderBase-1.md.txt#Google_Api_Gax_Rest_ClientBuilderBase_1_GoogleCredential), [CredentialsPath](https://docs.cloud.google.com/dotnet/docs/reference/Google.Api.Gax/latest/Google.Api.Gax.Rest.ClientBuilderBase-1.md.txt#Google_Api_Gax_Rest_ClientBuilderBase_1_CredentialsPath) or [JsonCredentials](https://docs.cloud.google.com/dotnet/docs/reference/Google.Api.Gax/latest/Google.Api.Gax.Rest.ClientBuilderBase-1.md.txt#Google_Api_Gax_Rest_ClientBuilderBase_1_JsonCredentials)
is used, [GetUniverseDomain()](https://github.com/googleapis/google-api-dotnet-client/blob/04e805147def8d2ec5b281c97ba77884dc123e0f/Src/Support/Google.Apis.Auth/OAuth2/GoogleCredential.cs) should be:

- The same as [UniverseDomain](https://docs.cloud.google.com/dotnet/docs/reference/Google.Api.Gax/latest/Google.Api.Gax.Rest.ClientBuilderBase-1.md.txt#Google_Api_Gax_Rest_ClientBuilderBase_1_UniverseDomain) if [UniverseDomain](https://docs.cloud.google.com/dotnet/docs/reference/Google.Api.Gax/latest/Google.Api.Gax.Rest.ClientBuilderBase-1.md.txt#Google_Api_Gax_Rest_ClientBuilderBase_1_UniverseDomain) has been set.
- The default universe domain otherwise.

<br />

### UseJwtAccessWithScopes

    public bool UseJwtAccessWithScopes { get; set; }

Returns whether or not self-signed JWTs will be used over OAuth tokens when OAuth scopes are explicitly set.

| **Property Value** ||
|---|---|
| **Type** | **Description** |
| `bool` |   |

**Remarks** In the base implementation, this defaults to `false` for maximum compatibility.
Subclasses which provide clients for services which support self-signed JWTs with scopes
may change this property value on construction, effectively changing the default to `true`
from the perspective of user code.

## Methods

### Build()

    public abstract TClient Build()

Builds the resulting client.

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `TClient` |   |

### BuildAsync(CancellationToken)

    public abstract Task<TClient> BuildAsync(CancellationToken cancellationToken = default)

Builds the resulting client asynchronously.

| **Parameter** ||
|---|---|
| **Name** | **Description** |
| `cancellationToken` | `CancellationToken` |

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `Task` |   |

### Configure(IServiceProvider)

    protected virtual void Configure(IServiceProvider provider)

Populates properties based on those set via dependency injection.

| **Parameter** ||
|---|---|
| **Name** | **Description** |
| `provider` | `IServiceProvider` The service provider to request dependencies from. |

**Remarks** <br />


Credentials are only requested from dependency injection if they are not already set
via any of [CredentialsPath](https://docs.cloud.google.com/dotnet/docs/reference/Google.Api.Gax/latest/Google.Api.Gax.Rest.ClientBuilderBase-1.md.txt#Google_Api_Gax_Rest_ClientBuilderBase_1_CredentialsPath),
[JsonCredentials](https://docs.cloud.google.com/dotnet/docs/reference/Google.Api.Gax/latest/Google.Api.Gax.Rest.ClientBuilderBase-1.md.txt#Google_Api_Gax_Rest_ClientBuilderBase_1_JsonCredentials), [Credential](https://docs.cloud.google.com/dotnet/docs/reference/Google.Api.Gax/latest/Google.Api.Gax.Rest.ClientBuilderBase-1.md.txt#Google_Api_Gax_Rest_ClientBuilderBase_1_Credential) or [GoogleCredential](https://docs.cloud.google.com/dotnet/docs/reference/Google.Api.Gax/latest/Google.Api.Gax.Rest.ClientBuilderBase-1.md.txt#Google_Api_Gax_Rest_ClientBuilderBase_1_GoogleCredential).


If credentials are requested, they are tried in the following order:

- ICredential
- GoogleCredential

<br />

### CreateServiceInitializer()

    protected virtual BaseClientService.Initializer CreateServiceInitializer()

Creates an initializer for the service. This method does not perform any validation.

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `BaseClientServiceInitializer` | An initializer for the service. |

### CreateServiceInitializerAsync(CancellationToken)

    protected virtual Task<BaseClientService.Initializer> CreateServiceInitializerAsync(CancellationToken cancellationToken)

Creates an initializer for the service asynchronously. This method does not perform any validation.

| **Parameter** ||
|---|---|
| **Name** | **Description** |
| `cancellationToken` | `CancellationToken` |

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `TaskBaseClientServiceInitializer` | An initializer for the service. |

### GetDefaultApplicationName()

    protected abstract string GetDefaultApplicationName()

Returns the default application name, used if no custom name is otherwise specified.

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `string` |   |

### GetHttpClientInitializer()

    protected virtual IConfigurableHttpClientInitializer GetHttpClientInitializer()

Obtains credentials synchronously. Override this method in a concrete builder type if more
credential mechanisms are supported.

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `IConfigurableHttpClientInitializer` |   |

### GetHttpClientInitializerAsync(CancellationToken)

    protected virtual Task<IConfigurableHttpClientInitializer> GetHttpClientInitializerAsync(CancellationToken cancellationToken)

Obtains credentials asynchronously. Override this method in a concrete builder type if more
credential mechanisms are supported.

| **Parameter** ||
|---|---|
| **Name** | **Description** |
| `cancellationToken` | `CancellationToken` |

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `TaskIConfigurableHttpClientInitializer` |   |

### GetScopedCredentialProvider()

    protected abstract ScopedCredentialProvider GetScopedCredentialProvider()

Returns the scoped credential provider for this builder.

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `ScopedCredentialProvider` |   |

### Validate()

    protected virtual void Validate()

Validates that the builder is in a consistent state for building. For example, it's invalid to call
[Build()](https://docs.cloud.google.com/dotnet/docs/reference/Google.Api.Gax/latest/Google.Api.Gax.Rest.ClientBuilderBase-1.md.txt#Google_Api_Gax_Rest_ClientBuilderBase_1_Build) on an instance which has both JSON credentials and a credentials path specified.

| **Exceptions** ||
|---|---|
| **Type** | **Description** |
| `InvalidOperationException` | The builder is in an invalid state. |

### ValidateAtMostOneNotNull(string, params object\[\])

    protected void ValidateAtMostOneNotNull(string message, params object[] values)

Validates that at most one of the given values is not null.

| **Parameters** ||
|---|---|
| **Name** | **Description** |
| `message` | `string` The message if the condition is violated. |
| `values` | `object` The values to check for nullity. |

| **Exceptions** ||
|---|---|
| **Type** | **Description** |
| `InvalidOperationException` | More than one value is null. |