< Summary

Information
Class: NexusLabs.Needlr.SemanticKernel.PluginScanners.ServiceProviderSemanticKernelPluginScanner
Assembly: NexusLabs.Needlr.SemanticKernel
File(s): /home/runner/work/needlr/needlr/src/NexusLabs.Needlr.SemanticKernel/PluginScanners/ServiceProviderSemanticKernelPluginScanner.cs
Line coverage
100%
Covered lines: 16
Uncovered lines: 0
Coverable lines: 16
Total lines: 39
Line coverage: 100%
Branch coverage
100%
Covered branches: 4
Total branches: 4
Branch coverage: 100%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
.ctor(...)100%11100%
ScanForPluginTypes()100%11100%
ScanForPluginTypes(...)100%44100%
HasKernelFunctions(...)100%11100%

File(s)

/home/runner/work/needlr/needlr/src/NexusLabs.Needlr.SemanticKernel/PluginScanners/ServiceProviderSemanticKernelPluginScanner.cs

#LineLine coverage
 1using Microsoft.Extensions.DependencyInjection;
 2using Microsoft.SemanticKernel;
 3
 4using System.Diagnostics.CodeAnalysis;
 5using System.Reflection;
 6
 7namespace NexusLabs.Needlr.SemanticKernel.PluginScanners;
 8
 9[RequiresUnreferencedCode("Service provider scanning uses reflection to discover types with [KernelFunction] methods.")]
 10[RequiresDynamicCode("Service provider scanning uses reflection APIs that may require dynamic code generation.")]
 411internal sealed class ServiceProviderSemanticKernelPluginScanner(
 412    IServiceProvider _root) :
 13    ISemanticKernelPluginScanner
 14{
 15    public IReadOnlyList<Type> ScanForPluginTypes()
 16    {
 417        var serviceCollection = _root.GetServiceCollection();
 418        var list = ScanForPluginTypes(serviceCollection)
 88019            .Where(t => serviceCollection.Any(sd => sd.ServiceType == t))
 420            .ToArray();
 421        return list;
 22    }
 23
 24    private static IReadOnlyList<Type> ScanForPluginTypes(IServiceCollection serviceCollection)
 25    {
 426        var list = serviceCollection
 14327            .Select(sd => sd.ServiceType)
 14328            .Where(t => t is { IsClass: true } && !t.IsAbstract)
 429            .Where(HasKernelFunctions)
 430            .Distinct()
 431            .ToArray();
 32
 433        return list;
 34    }
 35
 36    private static bool HasKernelFunctions(Type t) =>
 10737        t.GetMethods(BindingFlags.Instance | BindingFlags.Public)
 63838        .Any(m => m.IsDefined(typeof(KernelFunctionAttribute), inherit: true));
 39}