Show / Hide Table of Contents

Class ClientBuilderBase<TClient>

Base class for API-specific builders.

Inheritance
System.Object
ClientBuilderBase<TClient>
Inherited Members
System.Object.ToString()
System.Object.Equals(System.Object)
System.Object.Equals(System.Object, System.Object)
System.Object.ReferenceEquals(System.Object, System.Object)
System.Object.GetHashCode()
System.Object.GetType()
System.Object.MemberwiseClone()
Namespace: Google.Api.Gax.Grpc
Assembly: Google.Api.Gax.Grpc.dll
Syntax
public abstract class ClientBuilderBase<TClient>
Type Parameters
Name Description
TClient

The type of client created by this builder.

Constructors

ClientBuilderBase()

Creates a new instance with no settings.

Declaration
protected ClientBuilderBase()

Properties

CallInvoker

The call invoker to use, or null to create the call invoker when the client is built.

Declaration
public CallInvoker CallInvoker { get; set; }
Property Value
Type Description
CallInvoker

CanUseChannelPool

Returns whether or not a channel pool can be used if a channel is required. The default behavior is to return true if and only if no scopes, credentials or token access method have been specified. Derived classes should override this property if there are other reasons why the channel pool should not be used.

Declaration
protected virtual bool CanUseChannelPool { get; }
Property Value
Type Description
System.Boolean

ChannelCredentials

The channel credentials to use, or null if credentials are being provided in a different way.

Declaration
public ChannelCredentials ChannelCredentials { get; set; }
Property Value
Type Description
ChannelCredentials

CredentialsPath

The path to the credentials file to use, or null if credentials are being provided in a different way.

Declaration
public string CredentialsPath { get; set; }
Property Value
Type Description
System.String

DefaultGrpcAdapter

Returns the default GrpcAdapter to use if GrpcAdapter is not set.

Declaration
protected abstract GrpcAdapter DefaultGrpcAdapter { get; }
Property Value
Type Description
GrpcAdapter

EmulatorDetection

The emulator detection policy to apply when building a client. Derived classes which support emulators should create public properties which delegate to this one. The default value is None.

Declaration
protected EmulatorDetection EmulatorDetection { get; set; }
Property Value
Type Description
EmulatorDetection

Endpoint

The endpoint to connect to, or null to use the default endpoint.

Declaration
public string Endpoint { get; set; }
Property Value
Type Description
System.String

GrpcAdapter

The gRPC implementation to use, or null to use the default implementation.

Declaration
public GrpcAdapter GrpcAdapter { get; set; }
Property Value
Type Description
GrpcAdapter

JsonCredentials

The credentials to use as a JSON string, or null if credentials are being provided in a different way.

Declaration
public string JsonCredentials { get; set; }
Property Value
Type Description
System.String

Scopes

The scopes to use, or null to use the default scopes.

Declaration
public IReadOnlyList<string> Scopes { get; set; }
Property Value
Type Description
System.Collections.Generic.IReadOnlyList<System.String>

TokenAccessMethod

The token access method to use, or null if credentials are being provided in a different way.

Declaration
public Func<string, CancellationToken, Task<string>> TokenAccessMethod { get; set; }
Property Value
Type Description
System.Func<System.String, System.Threading.CancellationToken, System.Threading.Tasks.Task<System.String>>
Remarks

To use a GoogleCredential for credentials, set this property using a method group conversion, e.g. TokenAccessMethod = credential.GetAccessTokenForRequestAsync

UserAgent

A custom user agent to specify in the channel metadata, or null if no custom user agent is required.

Declaration
public string UserAgent { get; set; }
Property Value
Type Description
System.String

Methods

Build()

Builds the resulting client.

Declaration
public abstract TClient Build()
Returns
Type Description
TClient

BuildAsync(CancellationToken)

Builds the resulting client asynchronously.

Declaration
public abstract Task<TClient> BuildAsync(CancellationToken cancellationToken = default(CancellationToken))
Parameters
Type Name Description
System.Threading.CancellationToken cancellationToken
Returns
Type Description
System.Threading.Tasks.Task<TClient>

CopyCommonSettings<TOther>(ClientBuilderBase<TOther>)

Copies common settings from the specified builder into this one. This is a shallow copy.

Declaration
protected void CopyCommonSettings<TOther>(ClientBuilderBase<TOther> source)
Parameters
Type Name Description
ClientBuilderBase<TOther> source

The builder to copy from.

Type Parameters
Name Description
TOther

The other client type

CreateCallInvoker()

Creates a call invoker synchronously. Override this method in a concrete builder type if more call invoker mechanisms are supported. This implementation calls GetChannelCredentials() if no call invoker is specified.

Declaration
protected virtual CallInvoker CreateCallInvoker()
Returns
Type Description
CallInvoker

CreateCallInvokerAsync(CancellationToken)

Creates a call invoker asynchronously. Override this method in a concrete builder type if more call invoker mechanisms are supported. This implementation calls GetChannelCredentialsAsync(CancellationToken) if no call invoker is specified.

Declaration
protected virtual Task<CallInvoker> CreateCallInvokerAsync(CancellationToken cancellationToken)
Parameters
Type Name Description
System.Threading.CancellationToken cancellationToken
Returns
Type Description
System.Threading.Tasks.Task<CallInvoker>

GetChannelCredentials()

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

Declaration
protected virtual ChannelCredentials GetChannelCredentials()
Returns
Type Description
ChannelCredentials

GetChannelCredentialsAsync(CancellationToken)

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

Declaration
protected virtual Task<ChannelCredentials> GetChannelCredentialsAsync(CancellationToken cancellationToken)
Parameters
Type Name Description
System.Threading.CancellationToken cancellationToken
Returns
Type Description
System.Threading.Tasks.Task<ChannelCredentials>

GetChannelOptions()

Returns the options to use when creating a channel.

Declaration
protected virtual GrpcChannelOptions GetChannelOptions()
Returns
Type Description
GrpcChannelOptions

The options to use when creating a channel.

GetChannelPool()

Returns the channel pool to use when no other options are specified. This method is not called unless CanUseChannelPool returns true, so if a channel pool is unavailable, override that property to return false and throw an exception from this method.

Declaration
protected abstract ChannelPool GetChannelPool()
Returns
Type Description
ChannelPool

GetDefaultEndpoint()

Returns the endpoint for this builder type, used if no endpoint is otherwise specified.

Declaration
protected abstract string GetDefaultEndpoint()
Returns
Type Description
System.String

GetDefaultScopes()

Returns the default scopes for this builder type, used if no scopes are otherwise specified.

Declaration
protected abstract IReadOnlyList<string> GetDefaultScopes()
Returns
Type Description
System.Collections.Generic.IReadOnlyList<System.String>

GetEmulatorEnvironment(IEnumerable<String>, IEnumerable<String>, Func<String, String>)

Performs basic emulator detection and validation based on the given environment variables. This method is expected to be called by a derived class that supports emulators, in order to perform the common work of checking whether the emulator is configured in the environment.

Declaration
protected Dictionary<string, string> GetEmulatorEnvironment(IEnumerable<string> requiredEmulatorEnvironmentVariables, IEnumerable<string> allEmulatorEnvironmentVariables, Func<string, string> environmentVariableProvider = null)
Parameters
Type Name Description
System.Collections.Generic.IEnumerable<System.String> requiredEmulatorEnvironmentVariables

Required emulator environment variables.

System.Collections.Generic.IEnumerable<System.String> allEmulatorEnvironmentVariables

All emulator environment variables.

System.Func<System.String, System.String> environmentVariableProvider

The provider used to retrieve environment variables. This is used to faciliate testing, and defaults to using System.Environment.GetEnvironmentVariable(System.String).

Returns
Type Description
System.Collections.Generic.Dictionary<System.String, System.String>

A key/value mapping of the emulator environment variables to their values, or null if the emulator should not be used.

Remarks

If the emulator should not be used, either due to being disabled in EmulatorDetection or the appropriate environment variables not being set, this method returns null.

Otherwise, a dictionary is returned mapping every value in allEmulatorEnvironmentVariables to the value in the environment. Any missing, empty or whitespace-only values are mapped to a null reference in the returned dictionary, but the entry will still be present (so callers can use an indexer with the returned dictionary for every environment variable passed in).

Exceptions
Type Condition
System.InvalidOperationException

The configuration is inconsistent, e.g. due to some environment variables being set but not all the required ones, or any environment variables being set in a production-only environment.

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.

Declaration
protected virtual void Validate()
Exceptions
Type Condition
System.InvalidOperationException

The builder is in an invalid state.

ValidateAtMostOneNotNull(String, Object[])

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

Declaration
protected void ValidateAtMostOneNotNull(string message, params object[] values)
Parameters
Type Name Description
System.String message

The message if the condition is violated.

System.Object[] values

The values to check for nullity.

Exceptions
Type Condition
System.InvalidOperationException

More than one value is null.

ValidateOptionExcludesOthers(String, Object, Object[])

Validates that if controlling is not null, then every value in values is null.

Declaration
protected void ValidateOptionExcludesOthers(string message, object controlling, params object[] values)
Parameters
Type Name Description
System.String message

The message if the condition is violated.

System.Object controlling

The value controlling whether or not any other value can be non-null.

System.Object[] values

The values checked for non-nullity if controlling is non-null.

Back to top