Table of Contents

Class AsyncLocalQueryGuardSessionAccessor

Namespace
QueryGuard
Assembly
QueryGuard.Core.dll

The default IQueryGuardSessionAccessor, backed by AsyncLocal<T>.

public sealed class AsyncLocalQueryGuardSessionAccessor : IQueryGuardSessionAccessor
Inheritance
AsyncLocalQueryGuardSessionAccessor
Implements
Inherited Members

Remarks

AsyncLocal<T> flows with ExecutionContext, which is what makes an await boundary and Task.Run fan-out inside a request land in the right session without the application passing anything around.

The known limitation is the same one: work that deliberately suppresses context flow: through ExecutionContext.SuppressFlow, a custom scheduler that does not capture context, or fire-and-forget work started before the scope opened: will not be captured. That is documented behavior rather than a defect, and it is the reason DroppedRecordCount exists.

Activations form an immutable linked chain rather than a mutable stack, so a parent session is restored by pointing the accessor at the parent node. Nothing is shared or mutated between concurrent flows.

Properties

Current

Gets the session for the current asynchronous flow, or null when no scope is open.

Shared

The process-wide accessor used when no other one is supplied.

Methods

Activate(QueryGuardSession)

Makes session current for the calling flow and everything it awaits.