Table of Contents

Class ConnectionCacheServiceCollectionExtensions

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

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

public static class ConnectionCacheServiceCollectionExtensions
Inheritance
ConnectionCacheServiceCollectionExtensions
Inherited Members

Methods

AddIceRpcConnectionCache(IServiceCollection)

Adds a ConnectionCache and an IInvoker to this service collection.

public static IServiceCollection AddIceRpcConnectionCache(this IServiceCollection services)

Parameters

services IServiceCollection

The service collection to add services to.

Returns

IServiceCollection

The service collection.

Examples

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

IHostBuilder builder = Host.CreateDefaultBuilder(args);
builder.ConfigureServices(services => services.AddIceRpcConnectionCache());

The resulting singleton is a default connection cache. If you want to customize this connection cache, add an IOptions<TOptions> of ConnectionCacheOptions to your DI container:

IHostBuilder builder = Host.CreateDefaultBuilder(args);
builder.ConfigureServices(services =>
{
    services
        .AddOptions<ConnectionCacheOptions>()
        .Configure(options =>
            options.ConnectTimeout = TimeSpan.FromSeconds(30));

    services.AddIceRpcConnectionCache();
});

You can also inject a client transport:

The following example shows a connection cache that uses QUIC for icerpc connections and keeps the default duplex transport (tcp) for ice connections.
IHostBuilder builder = Host.CreateDefaultBuilder(args);
builder.ConfigureServices(services =>
    services
        // The IMultiplexedClientTransport singleton is implemented by QUIC.
        .AddSingleton<IMultiplexedClientTransport>(provider => new QuicClientTransport())
        .AddIceRpcConnectionCache());
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 connection cache options provided by the IOptions<TOptions> of ConnectionCacheOptions.