GFramework/docs/zh-CN/abstractions/core-abstractions.md
GeWuYou 1c2e68fc5a style(docs): 统一文档中IoC容器术语格式并优化架构生命周期代码
- 将文档中的"IOC"统一更正为"IoC"格式
- 重构ArchitectureLifecycle类构造函数使用主构造函数语法
- 移除私有字段前缀下划线,直接使用参数名称
- 修复配置访问权限问题,移除字段访问前缀下划线
- 调整组件注册方法泛型约束,提升类型安全
- 优化日志记录器访问方式,移除字段访问前缀下划线
- 重构销毁逻辑,分离组件清理和服务模块销毁流程
- 提取清理组件逻辑到独立方法,提升代码可读性
- 更新阶段转换和钩子通知中的对象引用方式
2026-03-17 12:50:43 +08:00

2.7 KiB
Raw Permalink Blame History

Core Abstractions

GFramework.Core.Abstractions 核心抽象接口定义

概述

GFramework.Core.Abstractions 包含了框架的所有核心接口定义,这些接口定义了组件之间的契约,实现了依赖倒置和面向接口编程。

核心接口

IArchitecture

应用程序架构接口:

public interface IArchitecture
{
    void Initialize();
    void Destroy();
    
    T GetModel<T>() where T : IModel;
    T GetSystem<T>() where T : ISystem;
    T GetUtility<T>() where T : IUtility;
    
    void RegisterModel(IModel model);
    void RegisterSystem(ISystem system);
    void RegisterUtility(IUtility utility);
}

IModel

数据模型接口:

public interface IModel
{
    void Init();
    void Dispose();
    
    IArchitecture Architecture { get; }
}

ISystem

业务逻辑系统接口:

public interface ISystem
{
    void Init();
    void Dispose();
    
    IArchitecture Architecture { get; }
}

IController

控制器接口:

public interface IController : IBelongToArchitecture
{
    void Init();
    void Dispose();
}

IUtility

工具类接口:

public interface IUtility
{
}

事件接口

IEvent

事件基接口:

public interface IEvent
{
}

IEventHandler

事件处理器接口:

public interface IEventHandler<TEvent> where TEvent : IEvent
{
    void Handle(TEvent @event);
}

命令查询接口

ICommand

命令接口:

public interface ICommand
{
    void Execute();
}

IQuery

查询接口:

public interface IQuery<TResult>
{
    TResult Execute();
}

依赖注入接口

IIocContainer

IoC 容器接口:

public interface IIocContainer
{
    void Register<TInterface, TImplementation>() where TImplementation : TInterface;
    void Register<TInterface>(TInterface instance);
    TInterface Resolve<TInterface>();
    bool IsRegistered<TInterface>();
}

生命周期接口

ILifecycle

组件生命周期接口:

public interface ILifecycle
{
    void OnInit();
    void OnDestroy();
}

使用示例

通过接口实现依赖注入

public class MyService : IMyService
{
    private readonly IArchitecture _architecture;
    
    public MyService(IArchitecture architecture)
    {
        _architecture = architecture;
    }
}

自定义事件

public class PlayerDiedEvent : IEvent
{
    public int PlayerId { get; set; }
    public Vector2 Position { get; set; }
}

相关文档