< Summary

Information
Class: NexusLabs.Needlr.Injection.Scrutor.ScrutorTypeRegistrar
Assembly: NexusLabs.Needlr.Injection.Scrutor
File(s): /home/runner/work/needlr/needlr/src/NexusLabs.Needlr.Injection.Scrutor/ScrutorTypeRegistrar.cs
Line coverage
100%
Covered lines: 34
Uncovered lines: 0
Coverable lines: 34
Total lines: 60
Line coverage: 100%
Branch coverage
100%
Covered branches: 18
Total branches: 18
Branch coverage: 100%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
RegisterTypesFromAssemblies(...)100%1818100%

File(s)

/home/runner/work/needlr/needlr/src/NexusLabs.Needlr.Injection.Scrutor/ScrutorTypeRegistrar.cs

#LineLine coverage
 1using Microsoft.Extensions.DependencyInjection;
 2
 3using System.Reflection;
 4
 5namespace NexusLabs.Needlr.Injection.Scrutor;
 6
 7/// <summary>
 8/// Registers types from assemblies using Scrutor.
 9/// </summary>
 10/// <remarks>
 11/// Scrutor does not traverse up the inheritance hierarchy of interfaces
 12/// to look for the <see cref="DoNotAutoRegisterAttribute"/>. As a result,
 13/// types that implement an interface with this attribute will still be
 14/// registered unless the attribute is applied directly to the type itself.
 15/// </remarks>
 16public sealed class ScrutorTypeRegistrar : ITypeRegistrar
 17{
 18    /// <inheritdoc />
 19    public void RegisterTypesFromAssemblies(
 20        IServiceCollection services,
 21        ITypeFilterer typeFilterer,
 22        IReadOnlyList<Assembly> assemblies)
 23    {
 3024        services
 6025            .Scan(x => x
 6026            .FromAssemblies(assemblies)
 6027            .AddClasses(classes =>
 3028                classes
 3029                    .WithoutAttribute<DoNotAutoRegisterAttribute>()
 55130                    .Where(type => !typeFilterer.IsTypeExcluded(type))
 58131                    .Where(type => typeFilterer.IsInjectableScopedType(type)),
 6032                publicOnly: false)
 6033            .AsSelfWithInterfaces()
 6034            .WithScopedLifetime());
 35
 3036        services
 6037            .Scan(x => x
 6038            .FromAssemblies(assemblies)
 6039            .AddClasses(classes =>
 3040                classes
 3041                    .WithoutAttribute<DoNotAutoRegisterAttribute>()
 55142                    .Where(type => !typeFilterer.IsTypeExcluded(type))
 58143                    .Where(type => typeFilterer.IsInjectableTransientType(type)),
 6044                publicOnly: false)
 6045            .AsSelfWithInterfaces()
 6046            .WithTransientLifetime());
 47
 3048        services
 6049            .Scan(x => x
 6050            .FromAssemblies(assemblies)
 6051            .AddClasses(classes =>
 3052                classes
 3053                    .WithoutAttribute<DoNotAutoRegisterAttribute>()
 55154                    .Where(type => !typeFilterer.IsTypeExcluded(type))
 58155                    .Where(type => typeFilterer.IsInjectableSingletonType(type)),
 6056                publicOnly: false)
 6057            .AsSelfWithInterfaces()
 6058            .WithSingletonLifetime());
 3059    }
 60}