< Summary

Information
Class: NexusLabs.Needlr.Hosting.IHostFactoryExtensions
Assembly: NexusLabs.Needlr.Hosting
File(s): /home/runner/work/needlr/needlr/src/NexusLabs.Needlr.Hosting/IHostFactoryExtensions.cs
Line coverage
60%
Covered lines: 6
Uncovered lines: 4
Coverable lines: 10
Total lines: 53
Line coverage: 60%
Branch coverage
100%
Covered branches: 2
Total branches: 2
Branch coverage: 100%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
Create(...)100%210%
EmptyConfig()100%210%
Create(...)100%11100%
Factory()100%22100%

File(s)

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

#LineLine coverage
 1using Microsoft.Extensions.Hosting;
 2
 3namespace NexusLabs.Needlr.Hosting;
 4
 5/// <summary>
 6/// Extension methods for <see cref="IHostFactory"/>.
 7/// </summary>
 8public static class IHostFactoryExtensions
 9{
 10    /// <summary>
 11    /// Creates an <see cref="IHost"/> using the specified options.
 12    /// </summary>
 13    /// <param name="factory">The host factory.</param>
 14    /// <param name="options">The options for creating the host.</param>
 15    /// <returns>The configured <see cref="IHost"/>.</returns>
 16    /// <exception cref="ArgumentNullException">Thrown when <paramref name="factory"/> or <paramref name="options"/> is 
 17    public static IHost Create(
 18        this IHostFactory factory,
 19        CreateHostOptions options)
 20    {
 021        ArgumentNullException.ThrowIfNull(factory);
 022        ArgumentNullException.ThrowIfNull(options);
 23
 024        static void EmptyConfig(HostApplicationBuilder _, CreateHostOptions __) { }
 025        return factory.Create(options, EmptyConfig);
 26    }
 27
 28    /// <summary>
 29    /// Creates an <see cref="IHost"/> using the specified options and configuration callback.
 30    /// </summary>
 31    /// <param name="factory">The host factory.</param>
 32    /// <param name="options">The options for creating the host.</param>
 33    /// <param name="configureCallback">Optional callback to configure the <see cref="HostApplicationBuilder"/>.</param>
 34    /// <returns>The configured <see cref="IHost"/>.</returns>
 35    /// <exception cref="ArgumentNullException">Thrown when <paramref name="factory"/> or <paramref name="options"/> is 
 36    public static IHost Create(
 37        this IHostFactory factory,
 38        CreateHostOptions options,
 39        Action<HostApplicationBuilder, CreateHostOptions>? configureCallback)
 40    {
 1141        ArgumentNullException.ThrowIfNull(factory);
 1142        ArgumentNullException.ThrowIfNull(options);
 43
 44        HostApplicationBuilder Factory()
 45        {
 1146            var hostApplicationBuilder = Host.CreateApplicationBuilder(options.Settings);
 1147            configureCallback?.Invoke(hostApplicationBuilder, options);
 1148            return hostApplicationBuilder;
 49        }
 50
 1151        return factory.Create(options, Factory);
 52    }
 53}