< Summary

Information
Class: IceRpc.Extensions.DependencyInjection.DispatcherBuilderExtensions
Assembly: IceRpc
File(s): /home/runner/work/icerpc-csharp/icerpc-csharp/src/IceRpc/Extensions/DependencyInjection/DispatcherBuilderExtensions.cs
Tag: 275_13775359185
Line coverage
50%
Covered lines: 6
Uncovered lines: 6
Coverable lines: 12
Total lines: 46
Line coverage: 50%
Branch coverage
N/A
Covered branches: 0
Total branches: 0
Branch coverage: N/A
Method coverage
33%
Covered methods: 1
Total methods: 3
Method coverage: 33.3%

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
Map(...)100%210%
UseDispatchInformation(...)100%11100%
UseFeature(...)100%210%

File(s)

/home/runner/work/icerpc-csharp/icerpc-csharp/src/IceRpc/Extensions/DependencyInjection/DispatcherBuilderExtensions.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="IDispatcherBuilder" /> to add a middleware that sets a feature.
 8/// </summary>
 9public static class DispatcherBuilderExtensions
 10{
 11    /// <summary>Registers a route to a service that uses the service's default path as the route path. If there is an
 12    /// existing route at the same path, it is replaced.</summary>
 13    /// <typeparam name="TService">The type of the DI service that will handle the requests. The implementation of this
 14    /// service must implement <see cref="IDispatcher" />.</typeparam>
 15    /// <param name="builder">The builder being configured.</param>
 16    /// <returns>This builder.</returns>
 17    /// <remarks>This default path is specific to services that implement Slice interfaces and
 18    /// <typeparamref name="TService" /> must correspond to an I{Name}Service interface generated by the Slice compiler.
 19    /// </remarks>
 20    public static IDispatcherBuilder Map<TService>(this IDispatcherBuilder builder) where TService : notnull =>
 021        builder.Map<TService>(typeof(TService).GetDefaultServicePath());
 22
 23    /// <summary>Adds a middleware that creates and inserts the <see cref="IDispatchInformationFeature" /> feature
 24    /// in all requests.</summary>
 25    /// <param name="builder">The builder being configured.</param>
 26    /// <returns>The builder.</returns>
 27    public static IDispatcherBuilder UseDispatchInformation(this IDispatcherBuilder builder) =>
 828        builder.Use(next => new InlineDispatcher((request, cancellationToken) =>
 5629        {
 5630            request.Features = request.Features.With<IDispatchInformationFeature>(
 5631                new DispatchInformationFeature(request));
 5632            return next.DispatchAsync(request, cancellationToken);
 6433        }));
 34
 35    /// <summary>Adds a middleware that sets a feature in all requests.</summary>
 36    /// <typeparam name="TFeature">The type of the feature.</typeparam>
 37    /// <param name="builder">The builder being configured.</param>
 38    /// <param name="feature">The value of the feature to set in all requests.</param>
 39    /// <returns>The builder.</returns>
 40    public static IDispatcherBuilder UseFeature<TFeature>(this IDispatcherBuilder builder, TFeature feature) =>
 041        builder.Use(next => new InlineDispatcher((request, cancellationToken) =>
 042        {
 043            request.Features = request.Features.With(feature);
 044            return next.DispatchAsync(request, cancellationToken);
 045        }));
 46}