ISC.FoxERP.Common
1.2.0
See the version list below for details.
dotnet add package ISC.FoxERP.Common --version 1.2.0
NuGet\Install-Package ISC.FoxERP.Common -Version 1.2.0
<PackageReference Include="ISC.FoxERP.Common" Version="1.2.0" />
<PackageVersion Include="ISC.FoxERP.Common" Version="1.2.0" />
<PackageReference Include="ISC.FoxERP.Common" />
paket add ISC.FoxERP.Common --version 1.2.0
#r "nuget: ISC.FoxERP.Common, 1.2.0"
#:package ISC.FoxERP.Common@1.2.0
#addin nuget:?package=ISC.FoxERP.Common&version=1.2.0
#tool nuget:?package=ISC.FoxERP.Common&version=1.2.0
ISC.FoxERP.Common
Thư viện dùng chung cho các module/service FoxERP (.NET 8): cùng một shape response, cùng một cách báo lỗi, cùng một cách xác thực và phân quyền, cùng một cách kết nối DB. Package chỉ chứa code hạ tầng và chuẩn chung, không chứa logic nghiệp vụ của module nào.
dotnet add package ISC.FoxERP.Common
Tên cài đặt là ISC.FoxERP.Common, còn namespace trong code là FoxErp.Common.Sdk:
using FoxErp.Common.Sdk;
Tính năng
| Tính năng | Điểm vào chính |
|---|---|
Response wrapper chuẩn (success, data, error, meta) |
ApiResponse<T>.Ok(...), .Fail(...) |
| Xử lý lỗi kỹ thuật tập trung | app.UseFoxErpExceptionHandling() |
| Xác thực JWT | services.AddFoxErpAuthentication(...) |
Phân quyền theo function_code và action |
services.AddFoxErpAuthorization(...), IFoxErpPermissionChecker |
| Chịu lỗi khi check quyền (cache, fail mode, circuit breaker) | Cấu hình FoxErpPlatform:Resilience (tùy chọn) |
JSON field snake_case |
SnakeCaseNamingPolicy |
| Kết nối SQL Server chuẩn (pooling, retry, circuit breaker) | AddFoxErpDbConnectionAsync(...) |
| Unit of Work | IUnitOfWork |
| Truy vết menu gốc | [InsideMenu(...)] |
Bắt đầu nhanh
// Program.cs
builder.Services.AddFoxErpAuthentication(builder.Configuration, builder.Environment.IsDevelopment());
builder.Services.AddFoxErpAuthorization(builder.Configuration);
var app = builder.Build();
app.UseFoxErpExceptionHandling(); // đặt TRƯỚC UseAuthentication()/UseAuthorization()
app.UseAuthentication();
app.UseAuthorization();
app.MapControllers();
Kiểm tra quyền chi tiết trong controller hoặc handler:
await permissionChecker.RequireAsync("<function_code>", "CREATE", User, ct);
// Thiếu quyền → tự throw ForbiddenActionException → HTTP 403 + AUTH_403
Trả response chuẩn:
return ApiResponse<IReadOnlyList<ItemDto>>.Ok(items, query.RequestId);
return ApiResponse<object>.Fail(MyModuleErrorCodes.SomeBusinessError, command.RequestId);
Mã lỗi kỹ thuật dùng chung
| Mã | HTTP | Retry | Khi nào |
|---|---|---|---|
REQ_TIMEOUT |
408 | có | Yêu cầu bị hủy hoặc quá thời gian |
SYS_500 |
500 | có | Exception không lường trước |
DB_500 |
500 | có | Lỗi cơ sở dữ liệu |
EXT_504 |
504 | có | Lỗi khi gọi hệ thống bên ngoài |
AUTH_401 |
401 | không | JWT thiếu hoặc sai |
AUTH_403 |
403 | không | Không có quyền thực hiện action |
AUTH_503 |
503 | có | Chưa xác minh được quyền (hệ thống phân quyền không phản hồi và fail mode không cho phép dùng cache hay cho qua) |
Mã lỗi nghiệp vụ riêng của từng module do module tự khai, kế thừa record ErrorCode.
Chịu lỗi khi check quyền (tùy chọn, từ 1.2.0)
Mặc định mỗi lần RequireAsync gọi hệ thống phân quyền một lần. Bật tùy chọn này để dùng cache trong RAM,
đặt timeout, ngắt mạch khi hệ thống phân quyền lỗi, và có quy tắc rõ ràng khi không xác minh được quyền:
{
"FoxErpPlatform": {
"Resilience": {
"Enabled": true,
"FailMode": { "Mode": "stale" },
"AlwaysClosedActions": [ "DELETE" ]
}
}
}
closed: không xác minh được thì chặn. Đây cũng là mode SDK tự dùng khi cấu hình bị hỏng.stale: dùng kết quả cache cũ trong thời hạn cho phép, hết hạn thì chặn.open: cho qua, cầnReasonvàExpiresAtUtc; chỉ dùng khi có chỉ đạo vận hành.AlwaysClosedActions: các action luôn bị chặn khi không lấy được quyền mới, kể cả ởstalevàopen.
Cấu hình sai thì ứng dụng không khởi động và báo rõ từng mục sai. SDK phát metric (Meter FoxErp.Auth)
và đăng ký health check foxerp-auth. Mặc định tính năng tắt, module không khai section này vẫn chạy
như các phiên bản trước.
Yêu cầu
- .NET 8
- Phụ thuộc:
Microsoft.AspNetCore.App(framework reference),Polly,Dapper,Microsoft.Data.SqlClient,VaultSharp,Microsoft.AspNetCore.Authentication.JwtBearer
Lịch sử phiên bản
| Version | Nội dung |
|---|---|
| 1.2.0 | Chịu lỗi khi check quyền (cache, fail mode, circuit breaker, metric, health check); mã lỗi AUTH_503; middleware lỗi không ghi đè response đã bắt đầu gửi; IFoxErpIamClient; overload RequireAsync và client nhận bearerToken; chuẩn hóa username (trim, chữ thường). |
| 1.0.0 | Bản đầu: response wrapper, middleware lỗi, xác thực JWT, phân quyền, kết nối DB, Unit of Work. |
Lưu ý khi nâng từ 1.0.0: IFoxErpPermissionClient có thêm 2 overload nhận bearerToken. Class nào tự cài
interface này cần bổ sung thêm 2 method.
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net8.0 is compatible. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. net9.0 was computed. net9.0-android was computed. net9.0-browser was computed. net9.0-ios was computed. net9.0-maccatalyst was computed. net9.0-macos was computed. net9.0-tvos was computed. net9.0-windows was computed. net10.0 was computed. 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. |
-
net8.0
- Dapper (>= 2.1.35)
- Microsoft.AspNetCore.Authentication.JwtBearer (>= 8.0.8)
- Microsoft.Data.SqlClient (>= 5.2.2)
- Microsoft.Extensions.Logging.Abstractions (>= 8.0.1)
- Polly (>= 8.4.2)
- VaultSharp (>= 1.13.0.1)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.