< Summary

Information
Class: Orchestrator.Infrastructure.TypeRegistrar
Assembly: Orchestrator
File(s): /home/runner/work/KicktippAi/KicktippAi/src/Orchestrator/Infrastructure/TypeRegistrar.cs
Line coverage
100%
Covered lines: 11
Uncovered lines: 0
Coverable lines: 11
Total lines: 42
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
.ctor(...)100%11100%
Build()100%11100%
Register(...)100%11100%
RegisterInstance(...)100%11100%
RegisterLazy(...)100%11100%

File(s)

/home/runner/work/KicktippAi/KicktippAi/src/Orchestrator/Infrastructure/TypeRegistrar.cs

#LineLine coverage
 1using Microsoft.Extensions.DependencyInjection;
 2using Spectre.Console.Cli;
 3
 4namespace Orchestrator.Infrastructure;
 5
 6/// <summary>
 7/// Bridges Microsoft.Extensions.DependencyInjection with Spectre.Console.Cli's <see cref="ITypeRegistrar"/>.
 8/// </summary>
 9/// <remarks>
 10/// Based on the canonical implementation from spectreconsole/examples:
 11/// <see href="https://github.com/spectreconsole/examples/blob/main/examples/Cli/Logging/Infrastructure/TypeRegistrar.cs
 12/// </remarks>
 13public sealed class TypeRegistrar : ITypeRegistrar
 14{
 15    private readonly IServiceCollection _builder;
 16
 117    public TypeRegistrar(IServiceCollection builder)
 18    {
 119        _builder = builder;
 120    }
 21
 22    public ITypeResolver Build()
 23    {
 124        return new TypeResolver(_builder.BuildServiceProvider());
 25    }
 26
 27    public void Register(Type service, Type implementation)
 28    {
 129        _builder.AddSingleton(service, implementation);
 130    }
 31
 32    public void RegisterInstance(Type service, object implementation)
 33    {
 134        _builder.AddSingleton(service, implementation);
 135    }
 36
 37    public void RegisterLazy(Type service, Func<object> func)
 38    {
 139        ArgumentNullException.ThrowIfNull(func);
 140        _builder.AddSingleton(service, _ => func());
 141    }
 42}