< Summary

Information
Class: TeleFlow.Framework.Updates.DefaultUpdateContextAccessor
Assembly: TeleFlow.Framework.Core
File(s): /_/src/TeleFlow.Framework.Core/Updates/DefaultUpdateContextAccessor.cs
Line coverage
94%
Covered lines: 16
Uncovered lines: 1
Coverable lines: 17
Total lines: 49
Line coverage: 94.1%
Branch coverage
75%
Covered branches: 6
Total branches: 8
Branch coverage: 75%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
get_IsAvailable()100%11100%
get_Current()100%22100%
TryGetCurrent(...)100%22100%
Initialize(...)50%2280%
Clear(...)50%22100%

File(s)

/_/src/TeleFlow.Framework.Core/Updates/DefaultUpdateContextAccessor.cs

#LineLine coverage
 1namespace TeleFlow.Framework.Updates;
 2
 3/// <summary>
 4/// Stores the current update context for one DI update scope so middleware, dispatchers, and scoped
 5/// application services observe the same update identity during processing.
 6/// </summary>
 7internal sealed class DefaultUpdateContextAccessor : IUpdateContextAccessor, IUpdateContextAccessorInitializer
 8{
 9    private UpdateContext? _current;
 10
 111    public bool IsAvailable => _current is not null;
 12
 913    public UpdateContext Current => _current ?? throw new InvalidOperationException(
 914        "No current update is available. IUpdateContextAccessor can only be used inside TeleFlow update processing, not 
 15
 16    public bool TryGetCurrent(out UpdateContext context)
 17    {
 3218        if (_current is null)
 19        {
 1020            context = null!;
 1021            return false;
 22        }
 23
 2224        context = _current;
 2225        return true;
 26    }
 27
 28    public void Initialize(UpdateContext context)
 29    {
 8730        ArgumentNullException.ThrowIfNull(context);
 31
 8732        if (_current is not null)
 33        {
 034            throw new InvalidOperationException("The current update accessor has already been initialized for this updat
 35        }
 36
 8737        _current = context;
 8738    }
 39
 40    public void Clear(UpdateContext context)
 41    {
 8742        ArgumentNullException.ThrowIfNull(context);
 43
 8744        if (ReferenceEquals(_current, context))
 45        {
 8746            _current = null;
 47        }
 8748    }
 49}