< Summary

Information
Class: NexusLabs.Needlr.Maui.MauiAppBuilderNeedlrExtensions
Assembly: NexusLabs.Needlr.Maui
File(s): /home/runner/work/needlr/needlr/src/NexusLabs.Needlr.Maui/MauiAppBuilderNeedlrExtensions.cs
Line coverage
100%
Covered lines: 6
Uncovered lines: 0
Coverable lines: 6
Total lines: 67
Line coverage: 100%
Branch coverage
N/A
Covered branches: 0
Total branches: 0
Branch coverage: N/A
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
UseNeedlr(...)100%11100%
UseNeedlr(...)100%11100%

File(s)

/home/runner/work/needlr/needlr/src/NexusLabs.Needlr.Maui/MauiAppBuilderNeedlrExtensions.cs

#LineLine coverage
 1using Microsoft.Maui.Hosting;
 2
 3using NexusLabs.Needlr.Injection;
 4
 5namespace NexusLabs.Needlr.Maui;
 6
 7/// <summary>
 8/// Extension methods that integrate Needlr's discovery into a user-controlled
 9/// <see cref="MauiAppBuilder"/>.
 10/// </summary>
 11/// <remarks>
 12/// <para>
 13/// <c>UseNeedlr</c> is a "reverse integration": Needlr adapts to the MAUI builder you already own
 14/// rather than taking over its creation. Call it from <c>MauiProgram.CreateMauiApp</c> after
 15/// <c>UseMauiApp&lt;App&gt;()</c>; every Needlr-discovered service is added to
 16/// <see cref="MauiAppBuilder.Services"/>, and MAUI builds and owns the single resulting provider.
 17/// </para>
 18/// </remarks>
 19/// <example>
 20/// <code>
 21/// public static MauiApp CreateMauiApp()
 22/// {
 23///     var builder = MauiApp.CreateBuilder();
 24///     builder
 25///         .UseMauiApp&lt;App&gt;()
 26///         .UseNeedlr(syringe =&gt; syringe.UsingSourceGen());
 27///
 28///     return builder.Build();
 29/// }
 30/// </code>
 31/// </example>
 32public static class MauiAppBuilderNeedlrExtensions
 33{
 34    /// <summary>
 35    /// Populates the builder's service collection with the registrations discovered by the
 36    /// supplied configured syringe.
 37    /// </summary>
 38    /// <param name="builder">The MAUI application builder to populate.</param>
 39    /// <param name="syringe">A configured syringe (for example <c>new Syringe().UsingSourceGen()</c>).</param>
 40    /// <returns>The same <paramref name="builder"/> instance, to allow chaining.</returns>
 41    /// <exception cref="System.ArgumentNullException">Thrown when any argument is <see langword="null"/>.</exception>
 42    public static MauiAppBuilder UseNeedlr(this MauiAppBuilder builder, ConfiguredSyringe syringe)
 43    {
 144        System.ArgumentNullException.ThrowIfNull(builder);
 145        System.ArgumentNullException.ThrowIfNull(syringe);
 146        return syringe.ForMaui().PopulateInto(builder);
 47    }
 48
 49    /// <summary>
 50    /// Populates the builder's service collection using a syringe configured by
 51    /// <paramref name="configure"/>. Use this overload to pick the discovery strategy inline, for
 52    /// example <c>builder.UseNeedlr(s =&gt; s.UsingSourceGen())</c>.
 53    /// </summary>
 54    /// <param name="builder">The MAUI application builder to populate.</param>
 55    /// <param name="configure">
 56    /// A callback that turns a fresh <see cref="Syringe"/> into a <see cref="ConfiguredSyringe"/>,
 57    /// typically by calling <c>UsingSourceGen()</c> or <c>UsingReflection()</c>.
 58    /// </param>
 59    /// <returns>The same <paramref name="builder"/> instance, to allow chaining.</returns>
 60    /// <exception cref="System.ArgumentNullException">Thrown when any argument is <see langword="null"/>.</exception>
 61    public static MauiAppBuilder UseNeedlr(this MauiAppBuilder builder, System.Func<Syringe, ConfiguredSyringe> configur
 62    {
 163        System.ArgumentNullException.ThrowIfNull(builder);
 164        System.ArgumentNullException.ThrowIfNull(configure);
 165        return builder.UseNeedlr(configure(new Syringe()));
 66    }
 67}