using System.Threading; using GFramework.Cqrs.Abstractions.Cqrs; using GFramework.Cqrs.Cqrs; namespace GFramework.Cqrs.Tests.Cqrs; /// /// 记录缓存 executor 复用场景下每次分发注入到 request handler 的上下文与实例身份。 /// internal sealed class DispatcherPipelineContextRefreshRequestHandler : CqrsContextAwareHandlerBase, IRequestHandler { private readonly int _instanceId = DispatcherPipelineContextRefreshState.AllocateHandlerInstanceId(); /// /// 记录当前 handler 实例收到的上下文,并返回稳定结果。 /// /// 当前请求。 /// 取消令牌。 /// 固定整数结果。 public ValueTask Handle( DispatcherPipelineContextRefreshRequest request, CancellationToken cancellationToken) { DispatcherPipelineContextRefreshState.RecordHandler(request.DispatchId, _instanceId, Context); return ValueTask.FromResult(7); } }