# ClientBuilderExtensions Methods

[Type overview](/orleans/docs/api/csharp/microsoft.orleans.core/orleans.hosting.clientbuilderextensions/)

## AddActivityPropagation(IClientBuilder) {#addactivitypropagation-this-orleans-hosting-iclientbuilder-9e596cb0}

[Dedicated page](/orleans/docs/api/csharp/microsoft.orleans.core/orleans.hosting.clientbuilderextensions/methods/addactivitypropagation-this-orleans-hosting-iclientbuilder-9e596cb0/)

[Source](https://github.com/dotnet/orleans/blob/e4e752cedecc2976811db49802c7a999b1f1c704/src/Orleans.Core/Core/ClientBuilderExtensions.cs#L168-L172)

```csharp
public static IClientBuilder AddActivityPropagation(this IClientBuilder builder)
```

Add `System.Diagnostics.Activity.Current` propagation through grain calls. Note: according to `System.Diagnostics.ActivitySource.StartActivity(System.String,System.Diagnostics.ActivityKind)` activity will be created only when any listener for activity exists `System.Diagnostics.ActivitySource.HasListeners` and `System.Diagnostics.ActivityListener.Sample` returns `System.Diagnostics.ActivitySamplingResult.PropagationData`.

### Parameters

- `builder` (`IClientBuilder`): The builder.

### Returns

The builder.

## AddClusterConnectionLostHandler(IClientBuilder, ConnectionToClusterLostHandler) {#addclusterconnectionlosthandler-this-orleans-hosting-iclientbuilder-orleans-conn-4cbbf864}

[Dedicated page](/orleans/docs/api/csharp/microsoft.orleans.core/orleans.hosting.clientbuilderextensions/methods/addclusterconnectionlosthandler-this-orleans-hosting-iclientbuilder-orleans-conn-4cbbf864/)

[Source](https://github.com/dotnet/orleans/blob/e4e752cedecc2976811db49802c7a999b1f1c704/src/Orleans.Core/Core/ClientBuilderExtensions.cs#L144-L145)

```csharp
public static IClientBuilder AddClusterConnectionLostHandler(this IClientBuilder builder, ConnectionToClusterLostHandler handler)
```

Registers a [ConnectionToClusterLostHandler](/orleans/docs/api/csharp/microsoft.orleans.core/orleans.connectiontoclusterlosthandler/) event handler.

### Parameters

- `builder` (`IClientBuilder`): The builder.
- `handler` (`ConnectionToClusterLostHandler`): The handler.

### Returns

The builder.

## AddClusterConnectionLostHandler(IClientBuilder, Func&lt;IServiceProvider, ConnectionToClusterLostHandler&gt;) {#addclusterconnectionlosthandler-this-orleans-hosting-iclientbuilder-system-func-312a9c3f}

[Dedicated page](/orleans/docs/api/csharp/microsoft.orleans.core/orleans.hosting.clientbuilderextensions/methods/addclusterconnectionlosthandler-this-orleans-hosting-iclientbuilder-system-func-312a9c3f/)

[Source](https://github.com/dotnet/orleans/blob/e4e752cedecc2976811db49802c7a999b1f1c704/src/Orleans.Core/Core/ClientBuilderExtensions.cs#L156-L157)

```csharp
public static IClientBuilder AddClusterConnectionLostHandler(this IClientBuilder builder, Func<IServiceProvider, ConnectionToClusterLostHandler> handlerFactory)
```

Registers a [ConnectionToClusterLostHandler](/orleans/docs/api/csharp/microsoft.orleans.core/orleans.connectiontoclusterlosthandler/) event handler.

### Parameters

- `builder` (`IClientBuilder`): The builder.
- `handlerFactory` (`Func<IServiceProvider, ConnectionToClusterLostHandler>`): The handler factory.

### Returns

The builder.

## AddClusterConnectionStatusObserver(IClientBuilder) {#addclusterconnectionstatusobserver-1-this-orleans-hosting-iclientbuilder-4ef9d5bd}

[Dedicated page](/orleans/docs/api/csharp/microsoft.orleans.core/orleans.hosting.clientbuilderextensions/methods/addclusterconnectionstatusobserver-1-this-orleans-hosting-iclientbuilder-4ef9d5bd/)

[Source](https://github.com/dotnet/orleans/blob/e4e752cedecc2976811db49802c7a999b1f1c704/src/Orleans.Core/Core/ClientBuilderExtensions.cs#L132-L133)

```csharp
public static IClientBuilder AddClusterConnectionStatusObserver<TObserver>(this IClientBuilder builder)
```

Registers a cluster connection status observer.

### Parameters

- `builder` (`IClientBuilder`)

## AddClusterConnectionStatusObserver(IClientBuilder, TObserver) {#addclusterconnectionstatusobserver-1-this-orleans-hosting-iclientbuilder-tobserv-4bbb8dd5}

[Dedicated page](/orleans/docs/api/csharp/microsoft.orleans.core/orleans.hosting.clientbuilderextensions/methods/addclusterconnectionstatusobserver-1-this-orleans-hosting-iclientbuilder-tobserv-4bbb8dd5/)

[Source](https://github.com/dotnet/orleans/blob/e4e752cedecc2976811db49802c7a999b1f1c704/src/Orleans.Core/Core/ClientBuilderExtensions.cs#L122-L123)

```csharp
public static IClientBuilder AddClusterConnectionStatusObserver<TObserver>(this IClientBuilder builder, TObserver observer)
```

Registers a cluster connection status observer.

### Parameters

- `builder` (`IClientBuilder`)
- `observer` (`TObserver`)

## AddGatewayCountChangedHandler(IClientBuilder, Func&lt;IServiceProvider, GatewayCountChangedHandler&gt;) {#addgatewaycountchangedhandler-this-orleans-hosting-iclientbuilder-system-func-sy-c7c50e4e}

[Dedicated page](/orleans/docs/api/csharp/microsoft.orleans.core/orleans.hosting.clientbuilderextensions/methods/addgatewaycountchangedhandler-this-orleans-hosting-iclientbuilder-system-func-sy-c7c50e4e/)

[Source](https://github.com/dotnet/orleans/blob/e4e752cedecc2976811db49802c7a999b1f1c704/src/Orleans.Core/Core/ClientBuilderExtensions.cs#L112-L113)

```csharp
public static IClientBuilder AddGatewayCountChangedHandler(this IClientBuilder builder, Func<IServiceProvider, GatewayCountChangedHandler> handlerFactory)
```

Registers a [GatewayCountChangedHandler](/orleans/docs/api/csharp/microsoft.orleans.core/orleans.gatewaycountchangedhandler/) event handler.

### Parameters

- `builder` (`IClientBuilder`)
- `handlerFactory` (`Func<IServiceProvider, GatewayCountChangedHandler>`)

## AddGatewayCountChangedHandler(IClientBuilder, GatewayCountChangedHandler) {#addgatewaycountchangedhandler-this-orleans-hosting-iclientbuilder-orleans-gatewa-3a1e087b}

[Dedicated page](/orleans/docs/api/csharp/microsoft.orleans.core/orleans.hosting.clientbuilderextensions/methods/addgatewaycountchangedhandler-this-orleans-hosting-iclientbuilder-orleans-gatewa-3a1e087b/)

[Source](https://github.com/dotnet/orleans/blob/e4e752cedecc2976811db49802c7a999b1f1c704/src/Orleans.Core/Core/ClientBuilderExtensions.cs#L103-L104)

```csharp
public static IClientBuilder AddGatewayCountChangedHandler(this IClientBuilder builder, GatewayCountChangedHandler handler)
```

Registers a [GatewayCountChangedHandler](/orleans/docs/api/csharp/microsoft.orleans.core/orleans.gatewaycountchangedhandler/) event handler.

### Parameters

- `builder` (`IClientBuilder`)
- `handler` (`GatewayCountChangedHandler`)

## Configure(IClientBuilder, Action&lt;TOptions&gt;) {#configure-1-this-orleans-hosting-iclientbuilder-system-action-toptions-572af3ec}

[Dedicated page](/orleans/docs/api/csharp/microsoft.orleans.core/orleans.hosting.clientbuilderextensions/methods/configure-1-this-orleans-hosting-iclientbuilder-system-action-toptions-572af3ec/)

[Source](https://github.com/dotnet/orleans/blob/e4e752cedecc2976811db49802c7a999b1f1c704/src/Orleans.Core/Core/ClientBuilderExtensions.cs#L83)

```csharp
public static IClientBuilder Configure<TOptions>(this IClientBuilder builder, Action<TOptions> configureOptions)
```

Registers an action used to configure a particular type of options.

### Parameters

- `builder` (`IClientBuilder`): The host builder.
- `configureOptions` (`Action<TOptions>`): The action used to configure the options.

### Returns

The client builder.

## Configure(IClientBuilder, IConfiguration) {#configure-1-this-orleans-hosting-iclientbuilder-microsoft-extensions-configurati-ed143e69}

[Dedicated page](/orleans/docs/api/csharp/microsoft.orleans.core/orleans.hosting.clientbuilderextensions/methods/configure-1-this-orleans-hosting-iclientbuilder-microsoft-extensions-configurati-ed143e69/)

[Source](https://github.com/dotnet/orleans/blob/e4e752cedecc2976811db49802c7a999b1f1c704/src/Orleans.Core/Core/ClientBuilderExtensions.cs#L95)

```csharp
public static IClientBuilder Configure<TOptions>(this IClientBuilder builder, IConfiguration configuration)
```

Registers a configuration instance which `TOptions` will bind against.

### Parameters

- `builder` (`IClientBuilder`): The host builder.
- `configuration` (`IConfiguration`): The configuration.

### Returns

The client builder.

## ConfigureServices(IClientBuilder, Action&lt;IServiceCollection&gt;) {#configureservices-this-orleans-hosting-iclientbuilder-system-action-microsoft-ex-76a88081}

[Dedicated page](/orleans/docs/api/csharp/microsoft.orleans.core/orleans.hosting.clientbuilderextensions/methods/configureservices-this-orleans-hosting-iclientbuilder-system-action-microsoft-ex-76a88081/)

[Source](https://github.com/dotnet/orleans/blob/e4e752cedecc2976811db49802c7a999b1f1c704/src/Orleans.Core/Core/ClientBuilderExtensions.cs#L69-L71)

```csharp
public static IClientBuilder ConfigureServices(this IClientBuilder builder, Action<IServiceCollection> configureDelegate)
```

Adds services to the container. This can be called multiple times and the results will be additive.

### Parameters

- `builder` (`IClientBuilder`): The host builder.
- `configureDelegate` (`Action<IServiceCollection>`)

### Returns

The same instance of the [IClientBuilder](/orleans/docs/api/csharp/microsoft.orleans.core/orleans.hosting.iclientbuilder/) for chaining.

## UseConnectionRetryFilter(IClientBuilder, Func&lt;Exception, CancellationToken, Task&lt;bool&gt;&gt;) {#useconnectionretryfilter-this-orleans-hosting-iclientbuilder-system-func-system-e131d793}

[Dedicated page](/orleans/docs/api/csharp/microsoft.orleans.core/orleans.hosting.clientbuilderextensions/methods/useconnectionretryfilter-this-orleans-hosting-iclientbuilder-system-func-system-e131d793/)

[Source](https://github.com/dotnet/orleans/blob/e4e752cedecc2976811db49802c7a999b1f1c704/src/Orleans.Core/Core/ClientBuilderExtensions.cs)

```csharp
public static IClientBuilder UseConnectionRetryFilter(this IClientBuilder builder, Func<Exception, CancellationToken, Task<bool>> connectionRetryFilter)
```

Configures the provided delegate as a connection retry filter, used to determine whether initial connection to the Orleans cluster should be retried after a failure.

### Parameters

- `builder` (`IClientBuilder`): The host builder.
- `connectionRetryFilter` (`Func<Exception, CancellationToken, Task<bool>>`): The connection retry filter.

### Returns

The same instance of the [IClientBuilder](/orleans/docs/api/csharp/microsoft.orleans.core/orleans.hosting.iclientbuilder/) for chaining.

## UseConnectionRetryFilter(IClientBuilder, IClientConnectionRetryFilter) {#useconnectionretryfilter-this-orleans-hosting-iclientbuilder-orleans-iclientconn-1307004b}

[Dedicated page](/orleans/docs/api/csharp/microsoft.orleans.core/orleans.hosting.clientbuilderextensions/methods/useconnectionretryfilter-this-orleans-hosting-iclientbuilder-orleans-iclientconn-1307004b/)

[Source](https://github.com/dotnet/orleans/blob/e4e752cedecc2976811db49802c7a999b1f1c704/src/Orleans.Core/Core/ClientBuilderExtensions.cs)

```csharp
public static IClientBuilder UseConnectionRetryFilter(this IClientBuilder builder, IClientConnectionRetryFilter connectionRetryFilter)
```

Configures the provided delegate as a connection retry filter, used to determine whether initial connection to the Orleans cluster should be retried after a failure.

### Parameters

- `builder` (`IClientBuilder`): The host builder.
- `connectionRetryFilter` (`IClientConnectionRetryFilter`): The connection retry filter.

### Returns

The same instance of the [IClientBuilder](/orleans/docs/api/csharp/microsoft.orleans.core/orleans.hosting.iclientbuilder/) for chaining.

## UseConnectionRetryFilter(IClientBuilder) {#useconnectionretryfilter-1-this-orleans-hosting-iclientbuilder-eee937f1}

[Dedicated page](/orleans/docs/api/csharp/microsoft.orleans.core/orleans.hosting.clientbuilderextensions/methods/useconnectionretryfilter-1-this-orleans-hosting-iclientbuilder-eee937f1/)

[Source](https://github.com/dotnet/orleans/blob/e4e752cedecc2976811db49802c7a999b1f1c704/src/Orleans.Core/Core/ClientBuilderExtensions.cs#L51)

```csharp
public static IClientBuilder UseConnectionRetryFilter<TConnectionRetryFilter>(this IClientBuilder builder)
```

Configures the provided `TConnectionRetryFilter` type as a connection retry filter, used to determine whether initial connection to the Orleans cluster should be retried after a failure.

### Parameters

- `builder` (`IClientBuilder`): The host builder.

### Returns

The same instance of the [IClientBuilder](/orleans/docs/api/csharp/microsoft.orleans.core/orleans.hosting.iclientbuilder/) for chaining.

## UseLocalhostClustering(IClientBuilder, int, string, string) {#uselocalhostclustering-this-orleans-hosting-iclientbuilder-int-string-string-92e0e0e9}

[Dedicated page](/orleans/docs/api/csharp/microsoft.orleans.core/orleans.hosting.clientbuilderextensions/methods/uselocalhostclustering-this-orleans-hosting-iclientbuilder-int-string-string-92e0e0e9/)

[Source](https://github.com/dotnet/orleans/blob/e4e752cedecc2976811db49802c7a999b1f1c704/src/Orleans.Core/Core/ClientBuilderExtensions.cs#L199)

```csharp
public static IClientBuilder UseLocalhostClustering(this IClientBuilder builder, int gatewayPort = 30000, string serviceId = "dev", string clusterId = "dev")
```

Configures the client to connect to a silo on the localhost.

### Parameters

- `builder` (`IClientBuilder`): The client builder.
- `gatewayPort` (`int`): The local silo's gateway port.
- `serviceId` (`string`): The service id.
- `clusterId` (`string`): The cluster id.

### Returns

The [IClientBuilder](/orleans/docs/api/csharp/microsoft.orleans.core/orleans.hosting.iclientbuilder/).

## UseLocalhostClustering(IClientBuilder, int[], string, string) {#uselocalhostclustering-this-orleans-hosting-iclientbuilder-int-array-1-string-st-89555d56}

[Dedicated page](/orleans/docs/api/csharp/microsoft.orleans.core/orleans.hosting.clientbuilderextensions/methods/uselocalhostclustering-this-orleans-hosting-iclientbuilder-int-array-1-string-st-89555d56/)

[Source](https://github.com/dotnet/orleans/blob/e4e752cedecc2976811db49802c7a999b1f1c704/src/Orleans.Core/Core/ClientBuilderExtensions.cs#L225-L245)

```csharp
public static IClientBuilder UseLocalhostClustering(this IClientBuilder builder, int[] gatewayPorts, string serviceId = "dev", string clusterId = "dev")
```

Configures the client to connect to a silo on the localhost.

### Parameters

- `builder` (`IClientBuilder`): The client builder.
- `gatewayPorts` (`int[]`): The local silo gateway ports.
- `serviceId` (`string`): The service id.
- `clusterId` (`string`): The cluster id.

### Returns

The [IClientBuilder](/orleans/docs/api/csharp/microsoft.orleans.core/orleans.hosting.iclientbuilder/).

## UseStaticClustering(IClientBuilder, Action&lt;OptionsBuilder&lt;StaticGatewayListProviderOptions&gt;&gt;) {#usestaticclustering-this-orleans-hosting-iclientbuilder-system-action-microsoft-092e0731}

[Dedicated page](/orleans/docs/api/csharp/microsoft.orleans.core/orleans.hosting.clientbuilderextensions/methods/usestaticclustering-this-orleans-hosting-iclientbuilder-system-action-microsoft-092e0731/)

[Source](https://github.com/dotnet/orleans/blob/e4e752cedecc2976811db49802c7a999b1f1c704/src/Orleans.Core/Core/ClientBuilderExtensions.cs)

```csharp
public static IClientBuilder UseStaticClustering(this IClientBuilder builder, Action<OptionsBuilder<StaticGatewayListProviderOptions>> configureOptions)
```

Configures the client to use static clustering.

### Parameters

- `builder` (`IClientBuilder`): The client builder.
- `configureOptions` (`Action<OptionsBuilder<StaticGatewayListProviderOptions>>`): The configure Options.

### Returns

The [IClientBuilder](/orleans/docs/api/csharp/microsoft.orleans.core/orleans.hosting.iclientbuilder/).

## UseStaticClustering(IClientBuilder, Action&lt;StaticGatewayListProviderOptions&gt;) {#usestaticclustering-this-orleans-hosting-iclientbuilder-system-action-orleans-co-2bdba142}

[Dedicated page](/orleans/docs/api/csharp/microsoft.orleans.core/orleans.hosting.clientbuilderextensions/methods/usestaticclustering-this-orleans-hosting-iclientbuilder-system-action-orleans-co-2bdba142/)

[Source](https://github.com/dotnet/orleans/blob/e4e752cedecc2976811db49802c7a999b1f1c704/src/Orleans.Core/Core/ClientBuilderExtensions.cs)

```csharp
public static IClientBuilder UseStaticClustering(this IClientBuilder builder, Action<StaticGatewayListProviderOptions> configureOptions)
```

Configures the client to use static clustering.

### Parameters

- `builder` (`IClientBuilder`): The client builder.
- `configureOptions` (`Action<StaticGatewayListProviderOptions>`): The configure Options.

### Returns

The [IClientBuilder](/orleans/docs/api/csharp/microsoft.orleans.core/orleans.hosting.iclientbuilder/).

## UseStaticClustering(IClientBuilder, IPEndPoint[]) {#usestaticclustering-this-orleans-hosting-iclientbuilder-params-system-net-ipendp-0cacbb97}

[Dedicated page](/orleans/docs/api/csharp/microsoft.orleans.core/orleans.hosting.clientbuilderextensions/methods/usestaticclustering-this-orleans-hosting-iclientbuilder-params-system-net-ipendp-0cacbb97/)

[Source](https://github.com/dotnet/orleans/blob/e4e752cedecc2976811db49802c7a999b1f1c704/src/Orleans.Core/Core/ClientBuilderExtensions.cs#L262)

```csharp
public static IClientBuilder UseStaticClustering(this IClientBuilder builder, params IPEndPoint[] endpoints)
```

Configures the client to use static clustering.

### Parameters

- `builder` (`IClientBuilder`): The client builder.
- `endpoints` (`IPEndPoint[]`): The gateway endpoints.

### Returns

The [IClientBuilder](/orleans/docs/api/csharp/microsoft.orleans.core/orleans.hosting.iclientbuilder/).
