< 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: 1856_27024993493
Line coverage
50%
Covered lines: 6
Uncovered lines: 6
Coverable lines: 12
Total lines: 45
Line coverage: 50%
Branch coverage
N/A
Covered branches: 0
Total branches: 0
Branch coverage: N/A
Method coverage
33%
Covered methods: 1
Fully covered methods: 1
Total methods: 3
Method coverage: 33.3%
Full 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>The default path is determined by the <see cref="DefaultServicePathAttribute"/> attribute on the
 18    /// <typeparamref name="TService"/> interface.</remarks>
 19    public static IDispatcherBuilder Map<TService>(this IDispatcherBuilder builder) where TService : notnull =>
 020        builder.Map<TService>(typeof(TService).GetDefaultServicePath());
 21
 22    /// <summary>Adds a middleware that creates and inserts the <see cref="IDispatchInformationFeature" /> feature
 23    /// in all requests.</summary>
 24    /// <param name="builder">The builder being configured.</param>
 25    /// <returns>The builder.</returns>
 26    public static IDispatcherBuilder UseDispatchInformation(this IDispatcherBuilder builder) =>
 827        builder.Use(next => new InlineDispatcher((request, cancellationToken) =>
 5628        {
 5629            request.Features = request.Features.With<IDispatchInformationFeature>(
 5630                new DispatchInformationFeature(request));
 5631            return next.DispatchAsync(request, cancellationToken);
 6432        }));
 33
 34    /// <summary>Adds a middleware that sets a feature in all requests.</summary>
 35    /// <typeparam name="TFeature">The type of the feature.</typeparam>
 36    /// <param name="builder">The builder being configured.</param>
 37    /// <param name="feature">The value of the feature to set in all requests.</param>
 38    /// <returns>The builder.</returns>
 39    public static IDispatcherBuilder UseFeature<TFeature>(this IDispatcherBuilder builder, TFeature feature) =>
 040        builder.Use(next => new InlineDispatcher((request, cancellationToken) =>
 041        {
 042            request.Features = request.Features.With(feature);
 043            return next.DispatchAsync(request, cancellationToken);
 044        }));
 45}