• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

icerpc / icerpc-csharp / 20856063721

09 Jan 2026 03:03PM UTC coverage: 83.441% (-0.2%) from 83.609%
20856063721

Pull #4216

github

web-flow
Merge de6640892 into 6beeff741
Pull Request #4216: Fix docfx DI examples

12063 of 14457 relevant lines covered (83.44%)

2897.72 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

67.65
src/IceRpc.Extensions.DependencyInjection/ClientConnectionServiceCollectionExtensions.cs
1
// Copyright (c) ZeroC, Inc.
2

3
using IceRpc.Transports;
4
using IceRpc.Transports.Quic;
5
using IceRpc.Transports.Tcp;
6
using Microsoft.Extensions.DependencyInjection;
7
using Microsoft.Extensions.DependencyInjection.Extensions;
8
using Microsoft.Extensions.Logging;
9
using Microsoft.Extensions.Options;
10
using System.Net.Quic;
11

12
namespace IceRpc.Extensions.DependencyInjection;
13

14
/// <summary>Provides an extension method for <see cref="IServiceCollection" /> to add a client connection.</summary>
15
public static class ClientConnectionServiceCollectionExtensions
16
{
17
    /// <summary>Adds a <see cref="ClientConnection" /> and an <see cref="IInvoker" /> to this service collection.
18
    /// </summary>
19
    /// <param name="services">The service collection to add services to.</param>
20
    /// <returns>The service collection.</returns>
21
    /// <remarks>This method uses the client connection options provided by the <see cref="IOptions{T}" /> of
22
    /// <see cref="ClientConnectionOptions" />.</remarks>
23
    /// <example>
24
    /// The following code adds a ClientConnection singleton to the service collection.
25
    /// <code source="../../docfx/examples/IceRpc.Extensions.DependencyInjection.Examples/AddIceRpcClientConnectionExamples.cs"
26
    /// region="ClientConnectionWithOptions" lang="csharp" />
27
    /// You can also inject a client transport:
28
    /// <list type="bullet">
29
    /// <item><description>an <see cref="IDuplexClientTransport" /> for the ice protocol</description></item>
30
    /// <item><description>an <see cref="IMultiplexedClientTransport" /> for the icerpc protocol</description></item>
31
    /// </list>
32
    /// For example, you can add a Slic over TCP client connection as follows:
33
    /// <code source="../../docfx/examples/IceRpc.Extensions.DependencyInjection.Examples/AddIceRpcClientConnectionExamples.cs"
34
    /// region="ClientConnectionWithSlic" lang="csharp" />
35
    /// If you want to customize the options of the default multiplexed transport (QUIC), you just need to inject an
36
    /// <see cref="IOptions{T}" /> of <see cref="QuicClientTransportOptions" />.
37
    /// </example>
38
    public static IServiceCollection AddIceRpcClientConnection(this IServiceCollection services) =>
39
        services
23✔
40
            .TryAddIceRpcClientTransport()
23✔
41
            .AddSingleton(provider =>
23✔
42
                new ClientConnection(
23✔
43
                    provider.GetRequiredService<IOptions<ClientConnectionOptions>>().Value,
23✔
44
                    provider.GetRequiredService<IDuplexClientTransport>(),
23✔
45
                    provider.GetRequiredService<IMultiplexedClientTransport>(),
23✔
46
                    provider.GetService<ILogger<ClientConnection>>()))
23✔
47
            .AddSingleton<IInvoker>(provider => provider.GetRequiredService<ClientConnection>());
25✔
48

49
    internal static IServiceCollection TryAddIceRpcClientTransport(this IServiceCollection services)
50
    {
27✔
51
        // The default duplex transport is TCP.
52
        services
27✔
53
            .AddOptions()
27✔
54
            .TryAddSingleton<IDuplexClientTransport>(
27✔
55
                provider => new TcpClientTransport(
27✔
56
                    provider.GetRequiredService<IOptions<TcpClientTransportOptions>>().Value));
27✔
57

58
        services
27✔
59
            .TryAddSingleton<IMultiplexedClientTransport>(
27✔
60
                provider =>
27✔
61
                {
×
62
                    if (OperatingSystem.IsLinux() || OperatingSystem.IsMacOS() || OperatingSystem.IsWindows())
×
63
                    {
×
64
                        if (QuicConnection.IsSupported)
×
65
                        {
×
66
                            return new QuicClientTransport(
×
67
                                provider.GetRequiredService<IOptions<QuicClientTransportOptions>>().Value);
×
68
                        }
27✔
69
                        throw new NotSupportedException(
×
70
                            "The default QUIC client transport is not available on this system. Please review the Platform Dependencies for QUIC in the .NET documentation.");
×
71
                    }
27✔
72
                    throw new PlatformNotSupportedException(
×
73
                        "The default QUIC client transport is not supported on this platform. You need to register an IMultiplexedClientTransport implementation in the service collection.");
×
74
                });
27✔
75

76
        return services;
27✔
77
    }
27✔
78
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc