From 50a71403bbd0a2e14c5bc13e704a1d167fcea436 Mon Sep 17 00:00:00 2001 From: GeWuYou <95328647+GeWuYou@users.noreply.github.com> Date: Wed, 11 Feb 2026 14:09:23 +0800 Subject: [PATCH] =?UTF-8?q?docs(ioc):=20=E6=9B=B4=E6=96=B0=20IoC=20?= =?UTF-8?q?=E5=AE=B9=E5=99=A8=E6=96=87=E6=A1=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 修复 IocContainer 链接路径指向正确文件位置 - 统一泛型方法语法格式,添加反引号标记如 Register、Get 等 - 修正代码块标记语法错误 - 更新注册和获取实例的方法示例代码格式 --- docs/zh-CN/core/ioc.md | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/docs/zh-CN/core/ioc.md b/docs/zh-CN/core/ioc.md index 9b15b7d..b826a35 100644 --- a/docs/zh-CN/core/ioc.md +++ b/docs/zh-CN/core/ioc.md @@ -7,7 +7,7 @@ IoC(Inversion of Control,控制反转)包提供了一个轻量级的依赖 ## 核心类 -### [`IocContainer`](IocContainer.cs) +### [`IocContainer`](../../GFramework.Core/ioc/IocContainer.cs) IoC 容器类,负责管理对象的注册和获取。 @@ -21,7 +21,7 @@ IoC 容器类,负责管理对象的注册和获取。 ## 核心方法 -### 1. Register 和 Register(Type, object) +### 1. Register`` 和 Register(Type, object) 注册一个实例到容器中。 @@ -46,7 +46,7 @@ container.Register(new GameSystem()); container.Register(new StorageUtility()); ``` -### 2. RegisterSingleton +### 2. RegisterSingleton`` 注册单例实例到容器中。一个类型只允许一个实例。 @@ -91,7 +91,7 @@ public void RegisterSystem(ISystem system) - `system`: 系统实例对象 -### 5. Get 和 GetAll +### 5. Get`` 和 GetAll`` 从容器中获取指定类型的实例。 @@ -116,7 +116,7 @@ var gameSystems = container.GetAll(); var unknownService = container.Get(); // null ``` -### 6. GetRequired +### 6. GetRequired`` 获取指定类型的必需实例,如果没有注册或注册了多个实例会抛出异常。 @@ -128,7 +128,7 @@ public T GetRequired() where T : class - 返回找到的唯一实例 -### 7. GetAllSorted +### 7. GetAllSorted`` 获取并排序(系统调度专用)。 @@ -439,7 +439,7 @@ public bool ContainsInstance(object instance) **使用示例:** -```csharp +``csharp var container = new IocContainer(); var service = new MyService(); @@ -609,7 +609,7 @@ public class GameArchitecture : Architecture ### 2. 使用接口类型注册 -```csharp +``csharp // ❌ 不推荐:直接使用实现类 RegisterSystem(new ConcreteSystem()); var system = GetSystem(); @@ -621,7 +621,7 @@ var system = GetSystem(); ### 3. 避免运行时频繁注册 -```csharp +``csharp // ❌ 不好:游戏运行时频繁注册 void Update() {