GFramework/GFramework.Core/Architectures/GameContextProvider.cs
gewuyou e3fa0db992 refactor(core): 收敛单活动上下文与预冻结查询
- 收敛 GameContext 为单活动上下文模型并保留类型别名兼容查找

- 统一 MicrosoftDiContainer 预冻结实例读取路径并补充 CQRS 注册阶段提示

- 更新 Core 测试、上下文文档与 ai-plan 追踪记录
2026-05-07 08:58:09 +08:00

35 lines
1.2 KiB
C#
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

// Copyright (c) 2025-2026 GeWuYou
// SPDX-License-Identifier: Apache-2.0
using GFramework.Core.Abstractions.Architectures;
namespace GFramework.Core.Architectures;
/// <summary>
/// 基于 GameContext 的默认上下文提供者。
/// 默认只面向当前活动上下文工作,而不是维护多个并存的全局上下文。
/// </summary>
public sealed class GameContextProvider : IArchitectureContextProvider
{
/// <summary>
/// 获取当前的架构上下文。
/// </summary>
/// <returns>架构上下文实例</returns>
public IArchitectureContext GetContext()
{
return GameContext.GetFirstArchitectureContext();
}
/// <summary>
/// 尝试获取指定类型的架构上下文。
/// 若当前活动上下文本身兼容 <typeparamref name="T" />,则无需显式类型别名也会返回成功。
/// </summary>
/// <typeparam name="T">架构上下文类型</typeparam>
/// <param name="context">输出的上下文实例</param>
/// <returns>如果成功获取则返回true否则返回false</returns>
public bool TryGetContext<T>(out T? context) where T : class, IArchitectureContext
{
return GameContext.TryGet(out context);
}
}