khteh/AspNetCoreWebApi · 文件 下载 ZIP
文件最后提交记录最后更新时间
README.md
以下内容由 AI 翻译,如有问题请点此提交 issue 反馈
AspNetCoreWebApi
一个基于 ASP.NET 10.0 的 Web API、SignalR 和 GRPC 项目,采用 Clean Architecture 快速搭建新项目。包含 Identity、带刷新令牌的 JWT 认证。应用设计同时由领域驱动设计(Domain-Driven-Design)和 Clean Architecture(https://blog.cleancoder.com/uncle-bob/2012/08/13/the-clean-architecture.html)驱动。它使用了 Command 和 Decorator 模式,以及 MediatR 进行进程内同步消息传递。
开发环境
- 将
nuget.config.FIXME复制到nuget.config - 从 GitHub 开发者设置中添加
Username和访问令牌
数据库设置
-
使用 PostgreSQL。
-
安装/更新 dotnet ef 工具:
$ dotnet tool install --global dotnet-ef $ dotnet tool update --global dotnet-ef -
要么运行应用程序 /
Web.Api.Infrastructure项目,数据库将自动创建;或者: -
应用数据库迁移以创建数据库。在
Web.Api.Infrastructure项目文件夹内的命令行中,使用 dotnet CLI 运行:$ cd src/Web.Api.Infrastructure $ dotnet ef database update -c AppDbContext $ dotnet ef database update -c AppIdentityDbContext
SignalR 客户端配置
npm install @microsoft/signalr- 将
node_modules\@microsoft\signalr\dist\browser的内容复制到wwwroot/lib/signalr
Visual Studio
- 生成 TLS 证书并将
localhost.pfx放入/tmp - 打开解决方案文件
AspNetCoreWebApi.slnx并构建/运行。
Visual Studio Code
Ctrl+Shift+B进行构建- 生成 TLS 证书并将
localhost.pfx放入/tmp F5启动调试会话
单元测试
- 安装 .Net Core Test Explorer
echo fs.inotify.max_user_instances=524288 | sudo tee -a /etc/sysctl.conf && sudo sysctl -p- https://github.com/dotnet/aspnetcore/issues/8449
启用 Swagger
要探索和测试可用的 API,只需运行项目并使用位于 http://localhost:{port}/swagger/index.html 的 Swagger UI
可用的 API 包括:
- POST
/api/accounts- 创建新用户。 - POST
/api/auth/login- 验证用户身份。 - POST
/api/auth/refreshtoken- 刷新过期的访问令牌。 - POST
/api/accounts/changepassword- 更改密码。 - POST
/api/accounts/resetpassword- 重置密码。 - GET
/api/accounts/lock/{id}- 锁定用户账户 ID。 - GET
/api/accounts/unlock/{id}- 解锁用户账户 ID。 - DELETE
/api/accounts/{username}- 使用用户名删除用户。 - GET
/api/protected- 用于测试基于角色的授权的受保护控制器。
日志
- 日志位于
/var/log/aspnetcore/logYYYYMMDD_*
Windows 11
- 进入 powershell:
powershell Get-Content -Path "c:\var\log\aspnetcore\logYYYYMMDD_<foo>" -Wait
持续集成:
- 已集成 CircleCI
Kubernetes
- 如果 ingress 使用前缀路径,需要将该前缀作为环境变量
PATH_BASE(或从 ConfigMap 挂载的appsettings.json)添加 - 由于已提交的问题 https://github.com/dotnet/aspnetcore/issues/42559,当
PATH_BASE不是/时,Swagger 无法正常工作