< Summary

Information
Class: NexusLabs.Needlr.SignalR.SignalRExtensions
Assembly: NexusLabs.Needlr.SignalR
File(s): /home/runner/work/needlr/needlr/src/NexusLabs.Needlr.SignalR/SignalRExtensions.cs
Line coverage
100%
Covered lines: 9
Uncovered lines: 0
Coverable lines: 9
Total lines: 84
Line coverage: 100%
Branch coverage
83%
Covered branches: 5
Total branches: 6
Branch coverage: 83.3%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
UseSignalRHubsWithReflection(...)83.33%66100%

File(s)

/home/runner/work/needlr/needlr/src/NexusLabs.Needlr.SignalR/SignalRExtensions.cs

#LineLine coverage
 1using Microsoft.AspNetCore.Builder;
 2using Microsoft.Extensions.DependencyInjection;
 3
 4using NexusLabs.Needlr.AspNet;
 5
 6using System.Diagnostics.CodeAnalysis;
 7
 8namespace NexusLabs.Needlr.SignalR;
 9
 10/// <summary>
 11/// Extension methods for configuring SignalR hub registration via Needlr.
 12/// </summary>
 13/// <remarks>
 14/// <para>
 15/// Two approaches are supported:
 16/// </para>
 17/// <list type="bullet">
 18/// <item><description>
 19/// <b>Reflection-based</b> (<see cref="UseSignalRHubsWithReflection"/>): discovers and maps hubs at
 20/// runtime. Convenient but incompatible with AOT/trimmed builds.
 21/// </description></item>
 22/// <item><description>
 23/// <b>Source-generated</b> (<c>app.MapGeneratedHubs()</c>): emits hub mappings at compile time.
 24/// Required for AOT/trimmed applications.
 25/// </description></item>
 26/// </list>
 27/// Hub endpoints are never mapped automatically. Call exactly one mapping extension
 28/// after building the application.
 29/// </remarks>
 30/// <example>
 31/// <code>
 32/// // Reflection-based (not AOT-safe)
 33/// app.UseSignalRHubsWithReflection();
 34///
 35/// // Source-generated (AOT-safe) — requires NexusLabs.Needlr.SignalR.Generators
 36/// app.MapGeneratedHubs();
 37/// </code>
 38/// </example>
 39public static class SignalRExtensions
 40{
 41    /// <summary>
 42    /// Registers SignalR hubs using reflection-based discovery.
 43    /// </summary>
 44    /// <remarks>
 45    /// <para>
 46    /// This method uses reflection to discover <see cref="IHubRegistrationPlugin"/> implementations
 47    /// and invoke <c>MapHub&lt;T&gt;()</c> at runtime.
 48    /// </para>
 49    /// <para>
 50    /// This is an explicit post-build operation. Needlr does not add the reflection
 51    /// mapper to automatic web-application plugin discovery.
 52    /// </para>
 53    /// <para>
 54    /// <strong>For AOT/trimmed applications</strong>, use the source-generated approach instead:
 55    /// <code>
 56    /// app.MapGeneratedHubs(); // Generated at compile-time, no reflection
 57    /// </code>
 58    /// </para>
 59    /// </remarks>
 60    /// <param name="app">The web application to configure.</param>
 61    /// <param name="pluginFactory">The plugin factory to use for discovering hub registration plugins.</param>
 62    /// <param name="assemblies">The assemblies to scan for hub registration plugins.</param>
 63    /// <returns>The web application for chaining.</returns>
 64    [RequiresUnreferencedCode("SignalR hub registration uses reflection to invoke MapHub<T>(). For AOT scenarios, use ap
 65    [RequiresDynamicCode("SignalR hub registration uses MakeGenericMethod() which requires dynamic code generation.")]
 66    public static WebApplication UseSignalRHubsWithReflection(
 67        this WebApplication app,
 68        IPluginFactory? pluginFactory = null,
 69        IEnumerable<System.Reflection.Assembly>? assemblies = null)
 70    {
 571        ArgumentNullException.ThrowIfNull(app);
 72
 473        pluginFactory ??= app.Services.GetRequiredService<IPluginFactory>();
 474        assemblies ??= app.Services.GetRequiredService<IReadOnlyList<System.Reflection.Assembly>>();
 75
 476        var assemblyList = assemblies as IReadOnlyList<System.Reflection.Assembly> ?? assemblies.ToList();
 477        new SignalRHubReflectionMapper().Map(
 478            app,
 479            assemblyList,
 480            pluginFactory);
 81
 482        return app;
 83    }
 84}