Class ClientBuilderBase<TClient> (4.0.0)

Stay organized with collections Save and categorize content based on your preferences.
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

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

Methods

Build()

public abstract TClient Build()

Builds the resulting client.

Returns
TypeDescription
TClient

BuildAsync(CancellationToken)

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

Builds the resulting client asynchronously.

Parameter
NameDescription
cancellationTokenCancellationToken
Returns
TypeDescription
Task<TClient>

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:

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 async 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
Task<BaseClientService.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 async 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
Task<IConfigurableHttpClientInitializer>

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, 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.