跳到主要内容

快速开始

5 分钟完成环境搭建与首次运行。

环境要求

工具版本说明
.NET SDK10.0+运行时
MySQL8.0+数据库
Redis6.0+缓存(可选)
MeiliSearch1.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/swaggerSwagger UI
https://localhost:7002/kit_api/rapi-docRapiDoc
https://localhost:7002/kit_api/healthchecks健康检查

其他宿主

宿主命令用途
Job.Hostdotnet run --project src/Services/Host/FreeKit.Job.Host定时任务
MessageHandler.Hostdotnet run --project src/Services/Host/FreeKit.MessageHandler.Host消息处理
Auth.Hostdotnet run --project src/Services/Auth/FreeKit.Auth.HostOAuth2 授权

模块注册

模块在 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 模块注册

相关文档