< Summary

Information
Class: NexusLabs.Needlr.Hosting.SyringeHostingExtensions
Assembly: NexusLabs.Needlr.Hosting
File(s): /home/runner/work/needlr/needlr/src/NexusLabs.Needlr.Hosting/SyringeHostingExtensions.cs
Line coverage
75%
Covered lines: 3
Uncovered lines: 1
Coverable lines: 4
Total lines: 77
Line coverage: 75%
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
ForHost(...)100%11100%
BuildHost(...)100%1150%

File(s)

/home/runner/work/needlr/needlr/src/NexusLabs.Needlr.Hosting/SyringeHostingExtensions.cs

#LineLine coverage
 1using Microsoft.Extensions.Hosting;
 2
 3using NexusLabs.Needlr.Injection;
 4
 5namespace NexusLabs.Needlr.Hosting;
 6
 7/// <summary>
 8/// Extension methods for configuring <see cref="ConfiguredSyringe"/> instances with generic host functionality.
 9/// </summary>
 10/// <example>
 11/// Source-gen first (recommended for AOT/trimming):
 12/// <code>
 13/// // With module initializer bootstrap (automatic):
 14/// var host = new Syringe()
 15///     .UsingSourceGen()
 16///     .ForHost()
 17///     .BuildHost();
 18///
 19/// await host.RunAsync();
 20/// </code>
 21///
 22/// Reflection-based (for dynamic scenarios):
 23/// <code>
 24/// var host = new Syringe()
 25///     .UsingReflection()
 26///     .ForHost()
 27///     .BuildHost();
 28///
 29/// await host.RunAsync();
 30/// </code>
 31/// </example>
 32public static class SyringeHostingExtensions
 33{
 34    /// <summary>
 35    /// Transitions the configured syringe to host mode, enabling host-specific configuration.
 36    /// </summary>
 37    /// <param name="syringe">The configured syringe to transition.</param>
 38    /// <returns>A new host syringe instance.</returns>
 39    /// <example>
 40    /// <code>
 41    /// var hostSyringe = new Syringe()
 42    ///     .UsingReflection()
 43    ///     .ForHost(); // Transition to host mode
 44    ///
 45    /// // Now you can use host-specific methods
 46    /// var host = hostSyringe
 47    ///     .UsingOptions(() => CreateHostOptions.Default.UsingArgs(args))
 48    ///     .BuildHost();
 49    /// </code>
 50    /// </example>
 51    public static HostSyringe ForHost(this ConfiguredSyringe syringe)
 52    {
 1553        ArgumentNullException.ThrowIfNull(syringe);
 1454        return new HostSyringe(syringe);
 55    }
 56
 57    /// <summary>
 58    /// Builds a host with the configured settings using the default HostFactory.
 59    /// </summary>
 60    /// <param name="syringe">The configured syringe to build from.</param>
 61    /// <returns>The configured <see cref="IHost"/>.</returns>
 62    /// <example>
 63    /// <code>
 64    /// // Direct build without additional host configuration
 65    /// var host = new Syringe()
 66    ///     .UsingReflection()
 67    ///     .BuildHost();
 68    ///
 69    /// await host.RunAsync();
 70    /// </code>
 71    /// </example>
 72    public static IHost BuildHost(this ConfiguredSyringe syringe)
 73    {
 174        ArgumentNullException.ThrowIfNull(syringe);
 075        return syringe.ForHost().BuildHost();
 76    }
 77}