| | | 1 | | namespace NexusLabs.Needlr.AgentFramework; |
| | | 2 | | |
| | | 3 | | /// <summary> |
| | | 4 | | /// Marks an interface for source generation of an <see cref="AsyncLocal{T}"/>-backed |
| | | 5 | | /// implementation. The generator emits an <c>internal sealed class</c> that implements |
| | | 6 | | /// the interface with proper scope nesting and dispose semantics. |
| | | 7 | | /// </summary> |
| | | 8 | | /// <remarks> |
| | | 9 | | /// <para> |
| | | 10 | | /// The interface must declare: |
| | | 11 | | /// <list type="bullet"> |
| | | 12 | | /// <item>A nullable read-only property named <c>Current</c> (determines the value type).</item> |
| | | 13 | | /// <item>A method returning <see cref="IDisposable"/> (the scope entry point).</item> |
| | | 14 | | /// </list> |
| | | 15 | | /// </para> |
| | | 16 | | /// <para> |
| | | 17 | | /// When <see cref="Mutable"/> is <see langword="true"/>, the generated implementation uses |
| | | 18 | | /// a mutable holder object in the <see cref="AsyncLocal{T}"/> slot so that writes from child |
| | | 19 | | /// async flows are visible to the parent scope (the pattern used by diagnostics accessors). |
| | | 20 | | /// </para> |
| | | 21 | | /// </remarks> |
| | | 22 | | /// <example> |
| | | 23 | | /// <code> |
| | | 24 | | /// [AsyncLocalScoped] |
| | | 25 | | /// public interface IMyContextAccessor |
| | | 26 | | /// { |
| | | 27 | | /// MyContext? Current { get; } |
| | | 28 | | /// IDisposable BeginScope(MyContext value); |
| | | 29 | | /// } |
| | | 30 | | /// // Generator emits: internal sealed class MyContextAccessor : IMyContextAccessor { ... } |
| | | 31 | | /// </code> |
| | | 32 | | /// </example> |
| | | 33 | | [AttributeUsage(AttributeTargets.Interface, AllowMultiple = false, Inherited = false)] |
| | | 34 | | public sealed class AsyncLocalScopedAttribute : Attribute |
| | | 35 | | { |
| | | 36 | | /// <summary> |
| | | 37 | | /// When <see langword="true"/>, the generated implementation uses a mutable holder object |
| | | 38 | | /// so that values set from child async flows are visible to the parent scope. |
| | | 39 | | /// Default is <see langword="false"/> (simple <see cref="AsyncLocal{T}"/> with scope restore). |
| | | 40 | | /// </summary> |
| | 0 | 41 | | public bool Mutable { get; init; } |
| | | 42 | | } |