Class ClientBuilderBase<TClient> (4.3.1)

public abstract class ClientBuilderBase<TClient>

Base class for API-specific builders.

Inheritance

object > ClientBuilderBase<TClient>

Namespace

GoogleGoogle.ApiGaxRest

Assembly

Google.Api.Gax.Rest.dll

Type Parameter

NameDescription
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
TypeDescription
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
TypeDescription
string

BaseUri

public string BaseUri { get; set; }

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

Property Value
TypeDescription
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
TypeDescription
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
TypeDescription
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
TypeDescription
GoogleCredential

HttpClientFactory

public IHttpClientFactory HttpClientFactory { get; set; }

An that will be used to obtain for making API Http calls. May be null, in which case an will be used.

Property Value
TypeDescription
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
TypeDescription
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
TypeDescription
string

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
TypeDescription
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
TypeDescription
TClient

BuildAsync(CancellationToken)

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

Builds the resulting client asynchronously.

Parameter
NameDescription
cancellationTokenCancellationToken
Returns
TypeDescription
Task

Configure(IServiceProvider)

protected virtual void Configure(IServiceProvider provider)

Populates properties based on those set via dependency injection.

Parameter
NameDescription
providerIServiceProvider

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
TypeDescription
BaseClientService.Initializer

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
NameDescription
cancellationTokenCancellationToken
Returns
TypeDescription
TaskBaseClientServiceBaseClientService.Initializer

An initializer for the service.

GetDefaultApplicationName()

protected abstract string GetDefaultApplicationName()

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

Returns
TypeDescription
string

GetHttpClientInitializer()

protected virtual IConfigurableHttpClientInitializer GetHttpClientInitializer()

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

Returns
TypeDescription
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
NameDescription
cancellationTokenCancellationToken
Returns
TypeDescription
TaskIConfigurableHttpClientInitializer

GetScopedCredentialProvider()

protected abstract ScopedCredentialProvider GetScopedCredentialProvider()

Returns the scoped credential provider for this builder.

Returns
TypeDescription
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
TypeDescription
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
NameDescription
messagestring

The message if the condition is violated.

valuesobject

The values to check for nullity.

Exceptions
TypeDescription
InvalidOperationException

More than one value is null.