Skip to content

IStreamQueryHandler<TQuery, TResult> interface

Namespace: Vitreous.Abstractions
Assembly: Vitreous.dll

Handles a stream query that reads state and produces items of type TResult lazily over time.

public interface IStreamQueryHandler<TQuery, TResult> where TQuery : IStreamQuery<TResult>

TQuery

The stream query type.

TResult

The type of each item yielded by the stream.

The handler returns a Result<T> wrapping the IAsyncEnumerable<T> so that setup failures (validation, authorization) can be signalled before any item is yielded. Once the stream is open, items flow as plain TResult.

Because C# does not allow yield return in a method that also returns ValueTask<…>, split the handler into two methods: Handle for setup/validation and a private iterator method for item production. For handlers with no validation, use the optional [StreamQueryHandler<TQuery, TResult>](/Vitreous/api/vitreous/abstractions/streamqueryhandler-2/) base class instead — it removes this split entirely.

Validates and opens the stream. On success, returns the lazy sequence of items. On failure, returns an Error before any item is produced.

ValueTask<Result<IAsyncEnumerable<TResult>>> Handle(TQuery query, CancellationToken ct = default)

query TQuery

ct CancellationToken

ValueTask<Result<IAsyncEnumerable<TResult>>>