Table of Contents

Class ClientConnectionServiceCollectionExtensions

Namespace
IceRpc.Extensions.DependencyInjection
Assembly
IceRpc.Extensions.DependencyInjection.dll

Provides an extension method for IServiceCollection to add a client connection.

public static class ClientConnectionServiceCollectionExtensions
Inheritance
ClientConnectionServiceCollectionExtensions
Inherited Members

Methods

AddIceRpcClientConnection(IServiceCollection)

Adds a ClientConnection and an IInvoker to this service collection.

public static IServiceCollection AddIceRpcClientConnection(this IServiceCollection services)

Parameters

services IServiceCollection

The service collection to add services to.

Returns

IServiceCollection

The service collection.

Examples

The following code adds a ClientConnection singleton to the service collection.

IHostBuilder builder = Host.CreateDefaultBuilder(args);
builder.ConfigureServices(services =>
{
    services
        .AddOptions<ClientConnectionOptions>()
        // We need to set at least ServerAddress in the options.
        .Configure(options =>
            options.ServerAddress = new ServerAddress(new Uri("icerpc://localhost")));

    services.AddIceRpcClientConnection();
});

You can also inject a client transport:

For example, you can add a QUIC client connection as follows:
IHostBuilder builder = Host.CreateDefaultBuilder(args);
builder.ConfigureServices(services =>
{
    services
        .AddOptions<ClientConnectionOptions>()
        // options.ClientAuthenticationOptions remains null which means we'll use the system certificates for this
        // secure QUIC connection.
        .Configure(options =>
            options.ServerAddress = new ServerAddress(new Uri("icerpc://localhost")));
    services
        // The IMultiplexedClientTransport singleton is implemented by QUIC.
        .AddSingleton<IMultiplexedClientTransport>(provider => new QuicClientTransport())
        .AddIceRpcClientConnection();
});
If you want to customize the options of the default transport (tcp), you just need to inject an IOptions<TOptions> of TcpClientTransportOptions.

Remarks

This method uses the client connection options provided by the IOptions<TOptions> of ClientConnectionOptions.