Class ClientBuilderBase<TClient> (4.8.0)

public abstract class ClientBuilderBase<TClient>

Base class for API-specific builders.

Inheritance

object > ClientBuilderBase<TClient>

Namespace

Google.Api.Gax.Rest

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) 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

GoogleCredential

public GoogleCredential GoogleCredential { get; set; }

The credentials to use as a GoogleCredential, or null if credentials are being provided in a different way. Note that unlike Credential, settings for 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 or JsonCredentials.

Property Value
Type Description
GoogleCredential

HttpClientFactory

public IHttpClientFactory HttpClientFactory { get; set; }

An IHttpClientFactory that will be used to obtain ConfigurableHttpClient for making API Http calls. May be null, in which case an HttpClientFactory 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

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

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 is used to build the base URI to connect to, unless BaseUri is set, in which case BaseUri will be used without further modification.

If default credentials or one of GoogleCredential, CredentialsPath or JsonCredentials is used, GetUniverseDomain() should be:

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

Credentials are only requested from dependency injection if they are not already set via any of CredentialsPath, JsonCredentials, Credential or GoogleCredential.

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

  • ICredential
  • GoogleCredential

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() 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.