mirror of
https://github.com/GeWuYou/GFramework.git
synced 2026-05-08 17:44:29 +08:00
- 修复 legacy bridge 测试装配与清理流程,改用 InternalsVisibleTo 和显式 handler 注册,补齐共享计数器重置与生命周期说明 - 优化 CommandExecutor、QueryExecutor 与相关模块的 runtime 契约,补充 XML 文档、nullable 注解和显式依赖解析 - 更新 legacy 异步 bridge 的取消语义、兼容文档回退边界以及 cqrs-rewrite active tracking/trace
34 lines
1.3 KiB
C#
34 lines
1.3 KiB
C#
// Copyright (c) 2025-2026 GeWuYou
|
|
// SPDX-License-Identifier: Apache-2.0
|
|
|
|
using GFramework.Core.Abstractions.Rule;
|
|
using GFramework.Core.Rule;
|
|
|
|
namespace GFramework.Core.Cqrs;
|
|
|
|
/// <summary>
|
|
/// 为 legacy Core CQRS bridge handler 提供共享的上下文注入辅助逻辑。
|
|
/// </summary>
|
|
internal abstract class LegacyCqrsDispatchHandlerBase : ContextAwareBase
|
|
{
|
|
/// <summary>
|
|
/// 在执行 legacy 命令或查询前,把当前架构上下文显式注入给支持 <see cref="IContextAware" /> 的目标对象。
|
|
/// </summary>
|
|
/// <param name="target">即将执行的 legacy 目标对象。</param>
|
|
/// <exception cref="ArgumentNullException"><paramref name="target" /> 为 <see langword="null" />。</exception>
|
|
/// <exception cref="InvalidOperationException">
|
|
/// 目标对象实现了 <see cref="IContextAware" />,但当前 handler 还没有可用的架构上下文。
|
|
/// </exception>
|
|
protected void PrepareTarget(object target)
|
|
{
|
|
ArgumentNullException.ThrowIfNull(target);
|
|
|
|
if (target is IContextAware contextAware)
|
|
{
|
|
var context = Context ?? throw new InvalidOperationException(
|
|
"Legacy CQRS bridge handler requires an active architecture context before executing a context-aware target.");
|
|
contextAware.SetContext(context);
|
|
}
|
|
}
|
|
}
|