TedToolkit.Scopes 2026.4.8

dotnet add package TedToolkit.Scopes --version 2026.4.8
                    
NuGet\Install-Package TedToolkit.Scopes -Version 2026.4.8
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="TedToolkit.Scopes" Version="2026.4.8" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="TedToolkit.Scopes" Version="2026.4.8" />
                    
Directory.Packages.props
<PackageReference Include="TedToolkit.Scopes" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add TedToolkit.Scopes --version 2026.4.8
                    
#r "nuget: TedToolkit.Scopes, 2026.4.8"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package TedToolkit.Scopes@2026.4.8
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=TedToolkit.Scopes&version=2026.4.8
                    
Install as a Cake Addin
#tool nuget:?package=TedToolkit.Scopes&version=2026.4.8
                    
Install as a Cake Tool

TedToolkit.Scopes

A lightweight, high-performance ambient context (scope) library for .NET. Track contextual state through synchronous and asynchronous call chains with built-in Roslyn analyzers for performance guidance.

Quick Start

Implement IScope and push it onto the ambient context:

using TedToolkit.Scopes;

public class LogScope(string context) : IScope
{
    public string Context => context;
    public void OnEntry() { }
    public void OnExit()  { }
}
// Async method — use Push()
using (new LogScope("request").Push())
{
    var current = Scope<LogScope>.Current; // LogScope instance
    await HandleAsync();
}

// Sync method — use FastPush() for best performance
using (new LogScope("sync").FastPush())
{
    var current = FastScope<LogScope>.Current;
    Process();
}

Scope Types

Type Async-safe Constraint Backing
Scope<T> Yes class, IScope AsyncLocal
ValueScope<T> Yes struct, IScope AsyncLocal
FastScope<T> No IScope Thread-static stack
ScopeBase<T> Yes Inherit from it AsyncLocal
ScopeRecord<T> Yes Inherit from it AsyncLocal
  • Scope<T> / ValueScope<T> — Push via .Push(). Flows through async/await and Task.Run.
  • FastScope<T> — Push via .FastPush(). ref struct, cannot cross await boundaries. Best performance.
  • ScopeBase<T> / ScopeRecord<T> — Abstract base classes that auto-enter the scope on construction.

Unified Access

Use ScopeValues to read the current scope regardless of how it was pushed:

// Class scopes
LogScope? current = ScopeValues.Class<LogScope>.Current;

// Struct scopes
ref readonly TraceScope current = ref ScopeValues.Struct<TraceScope>.Current;

Analyzers

ID Title
SCOPE001 Suggests FastScope<T> instead of Scope<T>/ValueScope<T> in sync methods
SCOPE002 Suggests .FastPush() instead of .Push() in sync methods

Both include automatic code fixes.

License

LGPL-3.0

Product Compatible and additional computed target framework versions.
.NET net5.0 was computed.  net5.0-windows was computed.  net6.0 is compatible.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 is compatible.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 is compatible.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed.  net9.0 is compatible.  net9.0-android was computed.  net9.0-browser was computed.  net9.0-ios was computed.  net9.0-maccatalyst was computed.  net9.0-macos was computed.  net9.0-tvos was computed.  net9.0-windows was computed.  net10.0 is compatible.  net10.0-android was computed.  net10.0-browser was computed.  net10.0-ios was computed.  net10.0-maccatalyst was computed.  net10.0-macos was computed.  net10.0-tvos was computed.  net10.0-windows was computed. 
.NET Core netcoreapp2.0 was computed.  netcoreapp2.1 was computed.  netcoreapp2.2 was computed.  netcoreapp3.0 was computed.  netcoreapp3.1 was computed. 
.NET Standard netstandard2.0 is compatible.  netstandard2.1 is compatible. 
.NET Framework net461 was computed.  net462 was computed.  net463 was computed.  net47 was computed.  net471 was computed.  net472 is compatible.  net48 is compatible.  net481 was computed. 
MonoAndroid monoandroid was computed. 
MonoMac monomac was computed. 
MonoTouch monotouch was computed. 
Tizen tizen40 was computed.  tizen60 was computed. 
Xamarin.iOS xamarinios was computed. 
Xamarin.Mac xamarinmac was computed. 
Xamarin.TVOS xamarintvos was computed. 
Xamarin.WatchOS xamarinwatchos was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages (2)

Showing the top 2 NuGet packages that depend on TedToolkit.Scopes:

Package Downloads
TedToolkit.Assertions

Some amazing assertion.

TedToolkit.Quantities

Struct Quantities Conversions

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
2026.4.8 83 4/8/2026
2026.1.31 997 1/31/2026
2026.1.9 106 1/9/2026
2026.1.7 102 1/7/2026
2025.12.23.1 340 12/23/2025
2025.12.23 321 12/23/2025
2025.12.17 413 12/17/2025
2025.12.12.2 279 12/12/2025
2025.12.12.1 270 12/12/2025
2025.12.12 262 12/12/2025
2025.12.9 607 12/9/2025
2025.11.25 364 11/25/2025
2025.11.24.3 337 11/24/2025
2025.11.24.2 348 11/24/2025
2025.11.24.1 342 11/24/2025
2025.11.24 358 11/24/2025
2025.11.21 546 11/21/2025
2025.11.20.4 552 11/20/2025
2025.11.20.3 549 11/20/2025
2025.11.20.2 553 11/20/2025
Loading failed