CoreMiddleware.Infrastructure
1.3.0
dotnet add package CoreMiddleware.Infrastructure --version 1.3.0
NuGet\Install-Package CoreMiddleware.Infrastructure -Version 1.3.0
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="CoreMiddleware.Infrastructure" Version="1.3.0" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="CoreMiddleware.Infrastructure" Version="1.3.0" />
<PackageReference Include="CoreMiddleware.Infrastructure" />
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add CoreMiddleware.Infrastructure --version 1.3.0
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
#r "nuget: CoreMiddleware.Infrastructure, 1.3.0"
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package CoreMiddleware.Infrastructure@1.3.0
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=CoreMiddleware.Infrastructure&version=1.3.0
#tool nuget:?package=CoreMiddleware.Infrastructure&version=1.3.0
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
Core Middleware 核心中介框架 (Core Middleware Framework)
提供 B2B SaaS 平台一致、安全且高度擴展的底層架構 SDK。 以 NuGet 套件形式發佈,由各業務服務(WebApi / Worker)引用。
🚀 專案導覽
本專案採用 Clean Architecture 與 Domain-Driven Design (DDD) 模式,分層發佈為四個 NuGet 套件,業務服務只需 dotnet add package 即可取得整套中介能力。
目錄結構
.
├── CoreMiddleware.Core/ # 領域層(Entities, Interfaces, Options) → NuGet
├── CoreMiddleware.Application/ # 應用層(Services 契約, DTOs) → NuGet
├── CoreMiddleware.Infrastructure/ # 基礎設施層(EF Core / PostgreSQL, Redis, Cognito)→ NuGet
├── CoreMiddleware.Analyzers/ # Roslyn 編譯期分析器(架構守門) → NuGet
├── CoreMiddleware.Tests/ # 自動化測試(xUnit)
├── docs/ # 本地技術文檔(架構、遷移、setup、範例)
├── nupkgs/ # 本地 pack 輸出
├── .husky/ # Git Hooks 品質管理配置
├── Directory.Build.props # 共用 NuGet metadata(Version / Authors)
├── publish-nuget.ps1 # NuGet 發佈腳本
└── USER_MANUAL.md # 消費端完整使用手冊(推薦先看這份)
本專案沒有 WebApi 專案。框架由 NuGet 套件形式提供,由下游服務(人資、財務等模組)的 WebApi 引用。
🏗️ 技術架構
本框架收斂以下企業級關鍵能力:
- 全域冪等性 (Idempotency) — Redis 鎖 + 響應快取,確保 API 不因重試而重複執行。
- 交易訊息保證 (Transactional Outbox) — 解決分散式環境下的最終一致性。
- 動態個資遮蔽 (PII Masking) — 符合 GDPR 的自動化欄位遮蔽。
- 多租戶分流 (Multi-Tenancy) — Zero-Trust 租戶解析 + 動態資料庫路由。
- 韌性通訊 (Resilience) — 內建 Polly 重試與熔斷。
- 多語系 (i18n) — 6 來源 chain(QueryString → Cookie → JWT → Profile → Accept-Language → Default)。
- 分散式限流 (Rate Limiting) — Redis Lua ZSET sliding window + FailOpen 降級。
- AWS Cognito 整合 — 非同步 federation + zero-trust tenant lookup。
🛠️ 快速開始 (Quick Start)
1. 環境需求
- .NET 10 SDK
- PostgreSQL 15+(已自 MySQL 遷移,詳見 docs/migrations/2026-04-mysql-to-postgresql.md)
- Redis 7.0+(冪等性、限流、快取)
- AWS Cognito(驗證與多租戶 federation;本地測試可用 stub)
2. 初始化開發環境
# 1. 還原套件
dotnet restore
# 2. 安裝 Git Hooks(Husky.NET)
dotnet tool restore
dotnet husky install
# 3. (選用)建立測試環境
powershell ./docs/scripts/setup-tests.ps1
3. 建置與測試
dotnet build CoreMiddleware.sln -c Release
dotnet test CoreMiddleware.sln -c Release
4. 發佈 NuGet 套件
# 只打包不推送(產出在 ./nupkgs/)
./publish-nuget.ps1 -Version 1.1.3 -PackOnly
# 推送到預設 feed(nuget.org)
./publish-nuget.ps1 -Version 1.1.3 -ApiKey <YOUR_KEY>
# 推送到內部 NuGet Server(自訂 -Source)
./publish-nuget.ps1 -Version 1.1.3 -ApiKey <YOUR_KEY> -Source <INTERNAL_FEED_URL>
詳細的消費端整合步驟請見 USER_MANUAL.md。
📚 技術文檔
本地文件(隨 repo,連結指向內部 GitLab develop 分支)
- 🎯 USER_MANUAL.md — 消費端完整使用手冊(新人從這裡開始)
- 🏗️ docs/architecture/ARCHITECTURE.md — 架構總覽
- 🔍 docs/architecture/ARCHITECTURE_AUDIT.md — 架構稽核
- 👨💻 docs/DEVELOPER_GUIDE.md — 開發者指南
- 📦 docs/examples/FULL_EXAMPLE.md — 從 Entity → Controller 完整範例
- 🔧 docs/setup/SETUP.md / docs/setup/GIT_HOOKS.md — 環境與 Git Hooks
- 🔄 docs/migrations/ — 重大遷移紀錄(MySQL → PostgreSQL 等)
架構規格文件(外部 TaleningDocument repo)
位於 D:\saas\TaleningDocument\docs\01_Core_Services\12_Core_Middleware\:
01_core_middleware_prd.md— 產品需求02_core_middleware_sa_schema.md— 系統分析(資料 Schema)03_core_middleware_sd_logic.md— 系統設計(邏輯)04_core_middleware_sd_impl.md— 系統設計(實作)04_core_middleware_test_cases.md— 測試案例
AI 協作配置
📦 NuGet 套件清單
| Package | 用途 |
|---|---|
CoreMiddleware.Core |
領域實體、介面、Options |
CoreMiddleware.Application |
應用服務契約、DTO |
CoreMiddleware.Infrastructure |
EF Core / PostgreSQL、Redis、Cognito、Outbox 實作 |
CoreMiddleware.Analyzers |
Roslyn 編譯期架構守門分析器 |
當前版本:見 Directory.Build.props 的 <Version>。
最後更新時間:2026-05-20(連結改用絕對 URL,確保 NuGet feed 上可點擊)
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net10.0 is compatible. net10.0-android was computed. net10.0-browser was computed. net10.0-ios was computed. net10.0-maccatalyst was computed. net10.0-macos was computed. net10.0-tvos was computed. net10.0-windows was computed. |
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
-
net10.0
- Ardalis.Specification (>= 8.0.0)
- Ardalis.Specification.EntityFrameworkCore (>= 8.0.0)
- AWSSDK.CognitoIdentityProvider (>= 4.0.103.1)
- BCrypt.Net-Next (>= 4.0.3)
- CoreMiddleware.Application (>= 1.3.0)
- CoreMiddleware.Core (>= 1.3.0)
- Dapper (>= 2.1.72)
- Microsoft.AspNetCore.Authentication.JwtBearer (>= 10.0.7)
- Microsoft.EntityFrameworkCore (>= 10.0.7)
- Microsoft.Extensions.Http.Resilience (>= 10.1.0)
- Microsoft.IdentityModel.JsonWebTokens (>= 8.1.2)
- Npgsql.EntityFrameworkCore.PostgreSQL (>= 10.0.1)
- Polly (>= 8.6.6)
- RabbitMQ.Client (>= 7.2.1)
- Scrutor (>= 5.0.2)
- StackExchange.Redis (>= 2.12.14)
- Swashbuckle.AspNetCore (>= 6.5.0)
- System.IdentityModel.Tokens.Jwt (>= 8.1.2)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.