< Summary

Information
Class: NexusLabs.Needlr.AgentFramework.Context.AgentExecutionContextAccessor
Assembly: NexusLabs.Needlr.AgentFramework
File(s): /home/runner/work/needlr/needlr/src/NexusLabs.Needlr.AgentFramework/Context/AgentExecutionContextAccessor.cs
Line coverage
100%
Covered lines: 12
Uncovered lines: 0
Coverable lines: 12
Total lines: 37
Line coverage: 100%
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
.cctor()100%11100%
get_Current()100%11100%
BeginScope(...)100%11100%
.ctor(...)100%11100%
Dispose()100%22100%

File(s)

/home/runner/work/needlr/needlr/src/NexusLabs.Needlr.AgentFramework/Context/AgentExecutionContextAccessor.cs

#LineLine coverage
 1namespace NexusLabs.Needlr.AgentFramework.Context;
 2
 3/// <summary>
 4/// <see cref="AsyncLocal{T}"/>-backed implementation of <see cref="IAgentExecutionContextAccessor"/>.
 5/// Each async flow sees its own context — concurrent orchestrations are naturally isolated.
 6/// </summary>
 7internal sealed class AgentExecutionContextAccessor : IAgentExecutionContextAccessor
 8{
 19    private static readonly AsyncLocal<IAgentExecutionContext?> CurrentContext = new();
 10
 11    /// <inheritdoc />
 2712    public IAgentExecutionContext? Current => CurrentContext.Value;
 13
 14    /// <inheritdoc />
 15    public IDisposable BeginScope(IAgentExecutionContext context)
 16    {
 2717        ArgumentNullException.ThrowIfNull(context);
 18
 2619        var previous = CurrentContext.Value;
 2620        CurrentContext.Value = context;
 2621        return new Scope(previous);
 22    }
 23
 2624    private sealed class Scope(IAgentExecutionContext? previous) : IDisposable
 25    {
 26        private bool _disposed;
 27
 28        public void Dispose()
 29        {
 2730            if (_disposed)
 131                return;
 32
 2633            _disposed = true;
 2634            CurrentContext.Value = previous;
 2635        }
 36    }
 37}