gewuyou 982249151e docs(zh-cn): 补齐文档元数据缺口
- 补齐 docs/zh-CN 多个栏目页面的 title 与 description frontmatter,清空完全缺 frontmatter 的历史页面
- 修复 multiplayer、source-generators 与 troubleshooting 触达页面暴露的 Markdown 结构和站内链接问题
- 更新 documentation-full-coverage-governance 的恢复点、验证结果与下一批 metadata 热点
2026-04-24 09:19:36 +08:00

111 lines
2.7 KiB
Markdown
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.

---
title: 快速开始
description: 通过只依赖 Core 的最小示例快速跑通 GFramework 基础架构。
---
# 快速开始
本页给出一个只依赖 `Core` 的最小路径,用来确认你已经成功接入 `Architecture``Model``System` 与旧版命令执行器。
> 说明:当前仓库同时存在旧版 `Command` / `Query` 执行器与新版 `CQRS` runtime。本页故意先用最短路径说明基础架构如何跑起来如果你要写新功能随后应继续阅读 [`../core/cqrs.md`](../core/cqrs.md)。
## 1. 安装最小依赖
```bash
dotnet add package GeWuYou.GFramework.Core
dotnet add package GeWuYou.GFramework.Core.Abstractions
```
## 2. 定义一个最小架构
```csharp
using GFramework.Core.Architectures;
public sealed class CounterArchitecture : Architecture
{
protected override void OnInitialize()
{
RegisterModel(new CounterModel());
RegisterSystem(new CounterSystem());
}
}
```
这里要点只有两个:
- 架构入口是 `Architecture`
- 当前版本使用 `protected override void OnInitialize()` 注册模型、系统和工具
## 3. 定义一个模型
```csharp
using GFramework.Core.Model;
using GFramework.Core.Property;
public sealed class CounterModel : AbstractModel
{
public BindableProperty<int> Count { get; } = new(0);
protected override void OnInit()
{
}
}
```
`BindableProperty<T>` 适合承载可观察状态;如果你只需要一个最小例子,保持 `OnInit()` 为空即可。
## 4. 定义一个系统
```csharp
using GFramework.Core.Systems;
public sealed class CounterSystem : AbstractSystem
{
protected override void OnInit()
{
}
}
```
## 5. 定义一个命令
```csharp
using GFramework.Core.Command;
public sealed class IncreaseCountCommand : AbstractCommand
{
protected override void OnExecute()
{
var model = GetModel<CounterModel>();
model.Count.Value += 1;
}
}
```
`AbstractCommand` 继承自 `ContextAwareBase`,所以命令内部可以直接访问 `GetModel<T>()``GetSystem<T>()` 等上下文方法。
## 6. 初始化并执行
```csharp
var architecture = new CounterArchitecture();
architecture.Initialize();
architecture.Context.SendCommand(new IncreaseCountCommand());
var count = architecture.Context.GetModel<CounterModel>().Count.Value;
Console.WriteLine(count); // 1
```
如果你能走通这一步,说明以下链路已经成立:
- 架构初始化
- 模型 / 系统注册
- 上下文访问
- 旧版命令执行
## 下一步
- 想切到推荐的新请求模型:看 [`../core/cqrs.md`](../core/cqrs.md)
- 想进入游戏层能力:看 [`../game/index.md`](../game/index.md)
- 想看模块入口而不是栏目页:回到对应模块目录下的 `README.md`