gewuyou 8209d7a29f docs(documentation): 收口公开文档口吻约束
- 修复公开 README 与 docs 页面中的反问式标题、维护者口吻和裸文件名链接标签
- 补充 AGENTS.md 与 gframework-doc-refresh 的 reader-facing 文档输出约束
- 更新 documentation-full-coverage-governance 的恢复点与验证记录
2026-04-25 09:27:06 +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。本页先用最短路径说明基础架构如何跑起来新功能优先采用 [CQRS 运行时](../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
```
如果你能走通这一步,说明以下链路已经成立:
- 架构初始化
- 模型 / 系统注册
- 上下文访问
- 旧版命令执行
## 下一步
- 新功能的请求 / 通知处理:看 [CQRS 运行时](../core/cqrs.md)
- 游戏层能力与接入顺序:看 [Game 模块总览](../game/index.md)
- 包目录与最小安装组合:看 [Core 运行时说明](https://github.com/GeWuYou/GFramework/blob/main/GFramework.Core/README.md)