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")));
services.AddIceRpcClientConnection();
});
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
.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.