< Summary

Information
Class: IceRpc.Extensions.DependencyInjection.InvokerBuilderExtensions
Assembly: IceRpc
File(s): /home/runner/work/icerpc-csharp/icerpc-csharp/src/IceRpc/Extensions/DependencyInjection/InvokerBuilderExtensions.cs
Tag: 275_13775359185
Line coverage
54%
Covered lines: 6
Uncovered lines: 5
Coverable lines: 11
Total lines: 35
Line coverage: 54.5%
Branch coverage
50%
Covered branches: 1
Total branches: 2
Branch coverage: 50%
Method coverage
50%
Covered methods: 1
Total methods: 2
Method coverage: 50%

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
Into(...)50%22100%
UseFeature(...)100%210%

File(s)

/home/runner/work/icerpc-csharp/icerpc-csharp/src/IceRpc/Extensions/DependencyInjection/InvokerBuilderExtensions.cs

#LineLine coverage
 1// Copyright (c) ZeroC, Inc.
 2
 3using IceRpc.Features;
 4
 5namespace IceRpc.Extensions.DependencyInjection;
 6
 7/// <summary>Provides extension methods for <see cref="IInvokerBuilder" /> to add the last invoker of an invocation
 8/// pipeline or to add a middleware that sets a feature.</summary>
 9public static class InvokerBuilderExtensions
 10{
 11    /// <summary>Sets the last invoker of the invocation pipeline to be a DI service managed by the service provider.
 12    /// </summary>
 13    /// <typeparam name="TService">The type of the DI service.</typeparam>
 14    /// <param name="builder">The builder being configured.</param>
 15    /// <returns>This builder.</returns>
 16    public static IInvokerBuilder Into<TService>(this IInvokerBuilder builder) where TService : IInvoker
 617    {
 618        object? into = builder.ServiceProvider.GetService(typeof(TService));
 619        return into is not null ? builder.Into((IInvoker)into) :
 620            throw new InvalidOperationException(
 621                $"Could not find service of type '{typeof(TService)}' in the service container.");
 622    }
 23
 24    /// <summary>Adds an interceptor that sets a feature in all requests.</summary>
 25    /// <typeparam name="TFeature">The type of the feature.</typeparam>
 26    /// <param name="builder">The builder being configured.</param>
 27    /// <param name="feature">The value of the feature to set.</param>
 28    /// <returns>The builder.</returns>
 29    public static IInvokerBuilder UseFeature<TFeature>(this IInvokerBuilder builder, TFeature feature) =>
 030        builder.Use(next => new InlineInvoker((request, cancellationToken) =>
 031        {
 032            request.Features = request.Features.With(feature);
 033            return next.InvokeAsync(request, cancellationToken);
 034        }));
 35}