< Summary

Information
Class: NexusLabs.Needlr.AgentFramework.FunctionScanners.ServiceProviderAgentFunctionScanner
Assembly: NexusLabs.Needlr.AgentFramework
File(s): /home/runner/work/needlr/needlr/src/NexusLabs.Needlr.AgentFramework/FunctionScanners/ServiceProviderAgentFunctionScanner.cs
Line coverage
0%
Covered lines: 0
Uncovered lines: 11
Coverable lines: 11
Total lines: 31
Line coverage: 0%
Branch coverage
0%
Covered branches: 0
Total branches: 4
Branch coverage: 0%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
.ctor(...)100%210%
ScanForFunctionTypes()0%2040%
HasAgentFunctions(...)100%210%

File(s)

/home/runner/work/needlr/needlr/src/NexusLabs.Needlr.AgentFramework/FunctionScanners/ServiceProviderAgentFunctionScanner.cs

#LineLine coverage
 1using Microsoft.Extensions.DependencyInjection;
 2
 3using NexusLabs.Needlr;
 4
 5using System.Diagnostics.CodeAnalysis;
 6using System.Reflection;
 7
 8namespace NexusLabs.Needlr.AgentFramework.FunctionScanners;
 9
 10[DoNotAutoRegister]
 11[RequiresUnreferencedCode("Service provider scanning uses reflection to discover types with [AgentFunction] methods.")]
 12[RequiresDynamicCode("Service provider scanning uses reflection APIs that may require dynamic code generation.")]
 013internal sealed class ServiceProviderAgentFunctionScanner(
 014    IServiceProvider _root) :
 15    IAgentFrameworkFunctionScanner
 16{
 17    public IReadOnlyList<Type> ScanForFunctionTypes()
 18    {
 019        var serviceCollection = _root.GetServiceCollection();
 020        return serviceCollection
 021            .Select(sd => sd.ServiceType)
 022            .Where(t => t is { IsClass: true } && !t.IsAbstract)
 023            .Where(HasAgentFunctions)
 024            .Distinct()
 025            .ToArray();
 26    }
 27
 28    private static bool HasAgentFunctions(Type t) =>
 029        t.GetMethods(BindingFlags.Instance | BindingFlags.Public)
 030         .Any(m => m.IsDefined(typeof(AgentFunctionAttribute), inherit: true));
 31}