< Summary - AsyncResponse (Release / net8.0+net10.0 / unit+integration)

Information
Class: Microsoft.Extensions.DependencyInjection.RedisAsyncResponseServiceCollectionExtensions
Assembly: AsyncResponse.Channels.Redis
File(s): /home/runner/work/AsyncResponse/AsyncResponse/src/Channels/AsyncResponse.Channels.Redis/ServiceCollectionExtensions.cs
Line coverage
100%
Covered lines: 21
Uncovered lines: 0
Coverable lines: 21
Total lines: 65
Line coverage: 100%
Branch coverage
100%
Covered branches: 20
Total branches: 20
Branch coverage: 100%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
WithRedisChannel(...)100%2020100%

File(s)

/home/runner/work/AsyncResponse/AsyncResponse/src/Channels/AsyncResponse.Channels.Redis/ServiceCollectionExtensions.cs

#LineLine coverage
 1using AsyncResponse;
 2using AsyncResponse.Channels.Redis;
 3using Microsoft.Extensions.DependencyInjection.Extensions;
 4
 5namespace Microsoft.Extensions.DependencyInjection;
 6
 7/// <summary>
 8/// DI registration for the Redis-backed AsyncResponse channel package.
 9/// </summary>
 10public static class RedisAsyncResponseServiceCollectionExtensions
 11{
 12    /// <summary>
 13    /// Registers Redis pub/sub as the response channel — behind <see cref="IAsyncResponsePublisher"/>,
 14    /// <see cref="IAsyncResponseSubscriber"/>, and <see cref="IRecoverableAsyncResponseSubscriber"/> —
 15    /// together with the durable Redis recovery-state store, so a response that arrives after the
 16    /// waiter died (e.g. a redeploy) can still resume or fail the owning flow. It also registers
 17    /// <see cref="IRecoverableAsyncResponseBuilder"/> for fluent durable recovery flows. The same
 18    /// channel instance serves the engine's recovery-state scanner and active-subscriber probe, so the
 19    /// watchdog works against Redis automatically.
 20    /// <para>
 21    /// Requires a <c>StackExchange.Redis.IConnectionMultiplexer</c> singleton registered by the
 22    /// host — reuse the application's existing multiplexer; don't create a second connection.
 23    /// Publisher/subscriber resolve to one shared instance: per-interface instances would split the
 24    /// channel's internal per-channel state.
 25    /// </para>
 26    /// </summary>
 27    public static AsyncResponseRegistrationBuilder WithRedisChannel(
 28        this AsyncResponseRegistrationBuilder builder,
 29        Action<RedisAsyncResponseOptions>? configure = null)
 30    {
 331        var services = builder.Services;
 332        services.AddOptions();
 333        if (configure is not null)
 34        {
 335            services.Configure(configure);
 36        }
 37
 38        // Durable recovery store; also the watchdog's recovery-state scanner.
 339        services.TryAddSingleton<RedisRecoveryStateStore>();
 340        services.Replace(ServiceDescriptor.Singleton<IRecoveryStateStore>(provider => provider.GetRequiredService<RedisR
 341        services.Replace(ServiceDescriptor.Singleton<IRecoveryStateScanner>(provider => provider.GetRequiredService<Redi
 42
 43        // Redis pub/sub response channel: publisher + subscriber + the watchdog's liveness probe,
 44        // all one shared instance.
 345        services.TryAddSingleton<RedisAsyncResponseChannel>();
 346        services.Replace(ServiceDescriptor.Singleton<IAsyncResponsePublisher>(provider => provider.GetRequiredService<Re
 347        services.Replace(ServiceDescriptor.Singleton<IRawAsyncResponsePublisher>(provider => provider.GetRequiredService
 348        services.Replace(ServiceDescriptor.Singleton<IAsyncResponseSubscriber>(provider => provider.GetRequiredService<R
 349        services.Replace(ServiceDescriptor.Singleton<IRecoverableAsyncResponseSubscriber>(provider => provider.GetRequir
 350        services.Replace(ServiceDescriptor.Singleton<IActiveSubscriberProbe>(provider => provider.GetRequiredService<Red
 51
 52        // Durable recovery capability: expose the recoverable fluent builder only when the Redis
 53        // channel package is the selected response channel. Plain IAsyncResponseBuilder still works
 54        // and shares the same implementation, but its static type does not offer recovery callbacks.
 355        services.Replace(ServiceDescriptor.Singleton<IRecoverableAsyncResponseBuilder>(provider => new RecoverableAsyncR
 356            provider.GetRequiredService<IRecoverableAsyncResponseSubscriber>(),
 357            provider.GetService<IWorkerTransport>(),
 358            provider.GetService<IAsyncResponseReplyTargetProvider>(),
 359            provider.GetRequiredService<AsyncResponseContextPropagation>())));
 360        services.Replace(ServiceDescriptor.Singleton<IAsyncResponseBuilder>(provider => provider.GetRequiredService<IRec
 61
 362        services.AddSingleton(new AsyncResponseChannelMarker("Redis"));
 363        return builder;
 64    }
 65}