AsyncLocalScopedAttribute
NexusLabs.Needlr.AgentFramework¶
NexusLabs.Needlr.AgentFramework¶
AsyncLocalScopedAttribute Class¶
Marks an interface for source generation of an System.Threading.AsyncLocal<>-backed
implementation. The generator emits an internal sealed class that implements
the interface with proper scope nesting and dispose semantics.
Inheritance System.Object 🡒 System.Attribute 🡒 AsyncLocalScopedAttribute
Example¶
[AsyncLocalScoped]
public interface IMyContextAccessor
{
MyContext? Current { get; }
IDisposable BeginScope(MyContext value);
}
// Generator emits: internal sealed class MyContextAccessor : IMyContextAccessor { ... }
Remarks¶
The interface must declare:
- A nullable read-only property named Current (determines the value type).
- A method returning System.IDisposable (the scope entry point).
When Mutable is true, the generated implementation uses a mutable holder object in the System.Threading.AsyncLocal<> slot so that writes from child async flows are visible to the parent scope (the pattern used by diagnostics accessors).
Properties¶
AsyncLocalScopedAttribute.Mutable Property¶
When true, the generated implementation uses a mutable holder object so that values set from child async flows are visible to the parent scope. Default is false (simple System.Threading.AsyncLocal<> with scope restore).