< Summary

Information
Class: IceRpc.Extensions.DependencyInjection.SliceServiceProviderExtensions
Assembly: IceRpc.Slice
File(s): /home/runner/work/icerpc-csharp/icerpc-csharp/src/IceRpc.Slice/DependencyInjection/SliceServiceProviderExtensions.cs
Tag: 1321_24790053727
Line coverage
100%
Covered lines: 20
Uncovered lines: 0
Coverable lines: 20
Total lines: 54
Line coverage: 100%
Branch coverage
75%
Covered branches: 3
Total branches: 4
Branch coverage: 75%
Method coverage
100%
Covered methods: 2
Fully covered methods: 2
Total methods: 2
Method coverage: 100%
Full method coverage: 100%

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
CreateSliceProxy(...)75%44100%
CreateSliceProxy(...)100%11100%

File(s)

/home/runner/work/icerpc-csharp/icerpc-csharp/src/IceRpc.Slice/DependencyInjection/SliceServiceProviderExtensions.cs

#LineLine coverage
 1// Copyright (c) ZeroC, Inc.
 2
 3using IceRpc.Slice;
 4
 5namespace IceRpc.Extensions.DependencyInjection;
 6
 7/// <summary>Provides extension methods for <see cref="IServiceProvider" /> to create Slice proxies.</summary>
 8public static class SliceServiceProviderExtensions
 9{
 10    /// <summary>Creates a Slice proxy with this service provider.</summary>
 11    /// <typeparam name="TProxy">The Slice proxy struct.</typeparam>
 12    /// <param name="provider">The service provider.</param>
 13    /// <param name="serviceAddress">The service address of the new proxy; null is equivalent to the default service
 14    /// address for the proxy type.</param>
 15    /// <returns>A new instance of <typeparamref name="TProxy" />.</returns>
 16    /// <remarks>The new proxy uses the <see cref="IInvoker" /> retrieved from <paramref name="provider" /> as its
 17    /// invocation pipeline, and the <see cref="SliceEncodeOptions" /> retrieved from <paramref name="provider" /> as
 18    /// its encode options.</remarks>
 19    public static TProxy CreateSliceProxy<TProxy>(this IServiceProvider provider, ServiceAddress? serviceAddress = null)
 20        where TProxy : struct, ISliceProxy
 421    {
 422        var invoker = (IInvoker?)provider.GetService(typeof(IInvoker));
 423        if (invoker is null)
 124        {
 125            throw new InvalidOperationException("Could not find service of type 'IInvoker' in the service container.");
 26        }
 27
 328        return serviceAddress is null ?
 329            new TProxy
 330            {
 331                EncodeOptions = (SliceEncodeOptions?)provider.GetService(typeof(SliceEncodeOptions)),
 332                Invoker = invoker
 333            }
 334            :
 335            new TProxy
 336            {
 337                EncodeOptions = (SliceEncodeOptions?)provider.GetService(typeof(SliceEncodeOptions)),
 338                Invoker = invoker,
 339                ServiceAddress = serviceAddress
 340            };
 341    }
 42
 43    /// <summary>Creates a Slice proxy with this service provider.</summary>
 44    /// <typeparam name="TProxy">The Slice proxy struct.</typeparam>
 45    /// <param name="provider">The service provider.</param>
 46    /// <param name="serviceAddressUri">The service address of the proxy as a URI.</param>
 47    /// <returns>A new instance of <typeparamref name="TProxy" />.</returns>
 48    /// <remarks>The new proxy uses the <see cref="IInvoker" /> retrieved from <paramref name="provider" /> as its
 49    /// invocation pipeline, and the <see cref="SliceEncodeOptions" /> retrieved from <paramref name="provider" /> as
 50    /// its encode options.</remarks>
 51    public static TProxy CreateSliceProxy<TProxy>(this IServiceProvider provider, Uri serviceAddressUri)
 52        where TProxy : struct, ISliceProxy =>
 253        provider.CreateSliceProxy<TProxy>(new ServiceAddress(serviceAddressUri));
 54}