Class IntentClientScope
- Namespace
- IntentSharp
- Assembly
- IntentSharp.dll
Makes an IntentClient ambient for the current async flow, so values can be asked to do things without passing the client at every call site:
using var scope = client.AsAmbient();
var order = await email.AIAsync<PurchaseRequest>("Extract the purchase request.");
The scope is AsyncLocal<T> state: it flows with awaits and tasks started inside it, is invisible to other requests and threads, and ends when disposed. A task started inside the scope that is still running after the scope was disposed no longer sees the client. There is still no process-wide default client.
public sealed class IntentClientScope : IDisposable
- Inheritance
-
objectIntentClientScope
- Implements
-
IDisposable
- Inherited Members
-
object.Equals(object)object.Equals(object, object)object.GetHashCode()object.GetType()object.ReferenceEquals(object, object)object.ToString()
- Extension Methods
Properties
- Current
The ambient client. Throws with guidance when no scope is open.
- CurrentOrNull
The ambient client, or null when no scope is open on this async flow.
Methods
- Dispose()
Ends the scope, and with it every scope opened inside it on this flow: the client that was ambient before this scope opened becomes ambient again. A scope that an enclosing scope already ended (because the enclosing scope was disposed first) changes nothing, so a client whose scope has ended never becomes ambient again. Disposing twice is a no-op. Current and CurrentOrNull skip ended scopes on every flow, including flows this call does not run on.