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
servicesIServiceCollectionThe 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")));
// options.ClientAuthenticationOptions remains null: this client connection uses
// the system Trusted Root CAs to validate the server certificate when establishing
// the underlying secure QUIC connection.
services.AddIceRpcClientConnection();
});
You can also inject a client transport:
- an IDuplexClientTransport for the ice protocol
- an IMultiplexedClientTransport for the icerpc protocol
For example, you can add a Slic over TCP client connection as follows:
IHostBuilder builder = Host.CreateDefaultBuilder(args);
builder.ConfigureServices(services =>
{
services
.AddOptions<ClientConnectionOptions>()
// Since options.ClientAuthenticationOptions is null, we use plain TCP (no TLS).
.Configure(options =>
options.ServerAddress = new ServerAddress(new Uri("icerpc://localhost")));
services
// The IMultiplexedClientTransport singleton is implemented by Slic.
.AddSingleton<IMultiplexedClientTransport>(
provider => new SlicClientTransport(
provider.GetRequiredService<IDuplexClientTransport>()))
.AddIceRpcClientConnection();
});
If you want to customize the options of the default multiplexed transport (QUIC), you just need to inject an IOptions<TOptions> of QuicClientTransportOptions.
Remarks
This method uses the client connection options provided by the IOptions<TOptions> of ClientConnectionOptions.