GeWuYou 56769cbf01 feat(architecture): 添加异步销毁功能支持
- 在 Architecture 中添加对 IAsyncDestroyable 接口的支持
- 将销毁集合类型从 IDestroyable 改为 object 以支持多种销毁接口
- 实现 DestroyAsync 方法提供异步销毁能力
- 保留旧的同步 Destroy 方法用于向后兼容
- 在 StateMachineSystem 中添加异步销毁状态的支持
- 添加 IAsyncDestroyable、IAsyncInitializable 和 IAsyncLifecycle 接口定义
- 更新测试代码以使用新的异步销毁方法
- 在架构销毁时清理依赖注入容器
2026-02-17 18:41:16 +08:00

47 lines
1.1 KiB
C#

using GFramework.Core.Abstractions.architecture;
using GFramework.Core.Abstractions.enums;
using GFramework.Core.Abstractions.lifecycle;
using GFramework.Core.Abstractions.system;
namespace GFramework.Core.Tests.system;
/// <summary>
/// 异步测试系统,实现 ISystem 和 IAsyncInitializable
/// </summary>
public sealed class AsyncTestSystem : ISystem, IAsyncInitializable
{
private IArchitectureContext _context = null!;
public bool Initialized { get; private set; }
public bool DestroyCalled { get; private set; }
public async Task InitializeAsync()
{
await Task.Delay(10);
Initialized = true;
}
public void SetContext(IArchitectureContext context)
{
_context = context;
}
public IArchitectureContext GetContext()
{
return _context;
}
public void Init()
{
// 同步 Init 不应该被调用
throw new InvalidOperationException("Sync Init should not be called");
}
public void Destroy()
{
DestroyCalled = true;
}
public void OnArchitecturePhase(ArchitecturePhase phase)
{
}
}