mirror of
https://github.com/GeWuYou/GFramework.git
synced 2026-05-08 09:34:30 +08:00
- 收敛 GameContext 为单活动上下文模型并保留类型别名兼容查找 - 统一 MicrosoftDiContainer 预冻结实例读取路径并补充 CQRS 注册阶段提示 - 更新 Core 测试、上下文文档与 ai-plan 追踪记录
35 lines
1.2 KiB
C#
35 lines
1.2 KiB
C#
// 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);
|
||
}
|
||
}
|