HaniBlindBox/.kiro/specs/api-infrastructure/tasks.md
2026-01-02 15:46:56 +08:00

3.5 KiB
Raw Blame History

Implementation Plan: API 基础架构搭建

Overview

本实现计划将 HoneyBox .NET 8 Web API 项目基础架构分解为可执行的任务,按顺序完成四层项目结构搭建、配置和验证。

Tasks

  • 1. 创建解决方案和项目结构

    • 1.1 创建解决方案和四个项目Api、Model、Core、Infrastructure
      • 使用 dotnet CLI 创建解决方案
      • 创建 HoneyBox.Api (webapi)
      • 创建 HoneyBox.Model (classlib)
      • 创建 HoneyBox.Core (classlib)
      • 创建 HoneyBox.Infrastructure (classlib)
      • Requirements: 1.1
    • 1.2 配置项目引用关系
      • Api → Core, Model
      • Core → Model, Infrastructure
      • Requirements: 1.2, 1.3, 1.4, 1.5
    • 1.3 配置各项目 NuGet 包
      • Model: EF Core, EF Core SqlServer
      • Core: Mapster
      • Infrastructure: Redis, Autofac
      • Api: Autofac.Extensions, Serilog, Swagger, JWT
      • Requirements: 2.1, 3.1, 4.1
  • 2. 配置 HoneyBox.Model 数据模型层

    • 2.1 创建 Base 目录和 ApiResponse 基类
      • 创建 ApiResponse 类
      • 创建 ApiResponse 泛型类
      • Requirements: 2.4
    • 2.2 创建 Data 目录和 DbContext
      • 使用 EF Core 脚手架从数据库生成实体
      • 配置 HoneyBoxDbContext
      • Requirements: 2.2, 2.3
    • 2.3 创建 Models 目录结构
      • 创建 Common.cs 通用模型
      • 创建按控制器分类的子目录User、Goods、Order 等)
      • Requirements: 2.5
  • 3. 配置 HoneyBox.Infrastructure 基础设施层

    • 3.1 创建 Cache 目录和缓存服务
      • 创建 ICacheService 接口
      • 创建 RedisCacheService 实现
      • Requirements: 3.1, 3.3, 3.4
    • 3.2 创建 Modules 目录和 Autofac 模块
      • 创建 ServiceModule 服务注册模块
      • 创建 InfrastructureModule 基础设施注册模块
      • Requirements: 3.2
    • 3.3 创建 External 目录结构
      • 创建 WeChat、Payment、Sms 子目录(预留)
      • Requirements: 3.1
  • 4. 配置 HoneyBox.Core 核心业务层

    • 4.1 创建 Mappings 目录和映射配置
      • 创建 MappingConfig 类
      • Requirements: 4.2
    • 4.2 创建 Services 和 Interfaces 目录
      • 创建目录结构
      • Requirements: 4.3
    • 4.3 创建 Constants 目录
      • 创建常量定义文件
      • Requirements: 4.4
  • 5. 配置 HoneyBox.Api 入口层

    • 5.1 配置 appsettings.json
      • 配置数据库连接字符串
      • 配置 Redis 连接字符串
      • 配置 Serilog 日志
      • Requirements: 2.6, 3.5, 5.2
    • 5.2 配置 Program.cs 主程序
      • 配置 Autofac 依赖注入
      • 配置 DbContext
      • 配置 Mapster
      • 配置 Serilog
      • 配置 Swagger
      • 配置 CORS
      • Requirements: 5.1, 5.2, 5.3, 5.5
    • 5.3 创建 Filters 目录和全局异常处理
      • 创建 GlobalExceptionFilter
      • Requirements: 5.4
  • 6. 创建健康检查接口

    • 6.1 创建 HealthController
      • 实现 /api/health 接口
      • 检查数据库连接状态
      • 检查 Redis 连接状态
      • 返回统一 ApiResponse 格式
      • Requirements: 6.1, 6.2, 6.3, 6.4, 6.5
  • 7. 验证和测试

    • 7.1 编译验证
      • 运行 dotnet build 确保编译通过
      • Requirements: 1.6
    • 7.2 运行验证
      • 启动应用
      • 访问 Swagger 文档
      • 调用健康检查接口
      • 检查日志输出
      • Requirements: 5.6, 6.1

Notes

  • 任务按顺序执行,后续任务依赖前置任务完成
  • 每个任务完成后进行编译验证
  • 最终通过健康检查接口验证整体架构