快速开始
5 分钟完成环境搭建与首次运行。
环境要求
| 工具 | 版本 | 说明 |
|---|---|---|
| .NET SDK | 10.0+ | 运行时 |
| MySQL | 8.0+ | 数据库 |
| Redis | 6.0+ | 缓存(可选) |
| MeiliSearch | 1.0+ | 搜索(可选) |
克隆仓库
git clone --recurse-submodules https://github.com/igeekfan/FreeKitModules.git
启动步骤
1. 还原依赖
dotnet restore FreeKitModules.sln
2. 配置数据库
编辑 src/Services/Host/FreeKit.Host/appsettings.Development.json:
{
"ConnectionStrings": {
"DefaultDB": "0",
"MySql": "Data Source=localhost;Port=3306;User ID=root;Password=123456;Initial Catalog=freekit;Charset=utf8mb4"
},
"Redis": {
"Host": "localhost:6379"
}
}
说明:
DefaultDB: "0"表示使用内存数据库(开发环境)- 设置为具体连接字符串时使用 MySQL
3. 启动主宿主
dotnet run --project src/Services/Host/FreeKit.Host
4. 访问服务
| 地址 | 说明 |
|---|---|
| https://localhost:7002/kit_api/swagger | Swagger UI |
| https://localhost:7002/kit_api/rapi-doc | RapiDoc |
| https://localhost:7002/kit_api/healthchecks | 健康检查 |
其他宿主
| 宿主 | 命令 | 用途 |
|---|---|---|
| Job.Host | dotnet run --project src/Services/Host/FreeKit.Job.Host | 定时任务 |
| MessageHandler.Host | dotnet run --project src/Services/Host/FreeKit.MessageHandler.Host | 消息处理 |
| Auth.Host | dotnet run --project src/Services/Auth/FreeKit.Auth.Host | OAuth2 授权 |
模块注册
模块在 src/Services/Host/FreeKit.DI/E.cs 中注册:
public static readonly Dictionary<string, Type> Modules = new(StringComparer.OrdinalIgnoreCase)
{
{ "identity", typeof(IdentityModuleStartup) },
{ "identity-inf", typeof(IdentityInfrastructureModuleStartup) },
{ "platform", typeof(PlatformModuleStartup) },
{ "cmskit", typeof(CmsKitModuleStartup) },
{ "member", typeof(MemberModuleStartup) },
};
新模块需要在 E.Modules 中添加注册才能生效。
常见问题
| 问题 | 解决方案 |
|---|---|
| 数据库连接失败 | 检查 appsettings.Development.json 中的连接字符串 |
| Swagger 无法访问 | 确保程序已启动,检查端口和 PathBase |
| 模块 API 不存在 | 检查 E.Modules 是否注册该模块 |
| FreeSql 未同步表结构 | 启用 UseAutoSyncStructure(true) |
| 依赖注入未生效 | 检查 Autofac 模块注册 |