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
IServiceCollectionThe 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:
- an IDuplexClientTransport for the ice protocol
- an IMultiplexedClientTransport for the icerpc protocol
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.