GJJ.Keystone.Abstractions 4.4.0

There is a newer version of this package available.
See the version list below for details.
dotnet add package GJJ.Keystone.Abstractions --version 4.4.0
                    
NuGet\Install-Package GJJ.Keystone.Abstractions -Version 4.4.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="GJJ.Keystone.Abstractions" Version="4.4.0" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="GJJ.Keystone.Abstractions" Version="4.4.0" />
                    
Directory.Packages.props
<PackageReference Include="GJJ.Keystone.Abstractions" />
                    
Project file
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 GJJ.Keystone.Abstractions --version 4.4.0
                    
#r "nuget: GJJ.Keystone.Abstractions, 4.4.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 GJJ.Keystone.Abstractions@4.4.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=GJJ.Keystone.Abstractions&version=4.4.0
                    
Install as a Cake Addin
#tool nuget:?package=GJJ.Keystone.Abstractions&version=4.4.0
                    
Install as a Cake Tool

GJJ.Keystone.Abstractions

GJJ Keystone 体系的契约层:只放跨层共用的结果类型、常量、注解、领域基元与中立接口,不依赖 ASP.NET Core,也不引入第三方运行时。

S_ApiResult 完整契约(含 code 取值、字段命名、异常处理约定、前端取值规范)见:docs/cross-cutting/API响应契约_S_ApiResult与异常处理.md DM8(达梦)适配指南:docs/cross-cutting/DM8达梦数据库适配指南.md 接入新服务的"从 0 到 1"清单:Sample.GJJService/README.md

为什么独立成包

  • 让 Application / Domain / Infrastructure 等任意层都能直接引用,而不会顺带把 Web 依赖、加密实现、HTTP 客户端拉进来。
  • 与 GJJ.Keystone.Toolkit(运行时工具)和 GJJ.Keystone.AspNetCore(Web 扩展)分离,保证依赖图自上而下,避免循环。
  • 包内只有数据契约、注解与中立接口,体积小、迭代慢,适合作为多版本服务长期共用的基线。

内容概览

结果类型(Contracts/)

类型 用途
CommandResult / CommandResult<TId> 命令执行结果(无数据 / 带主键),含 Success(...) / Fail(...) 流式 API
QueryResult<T> 查询执行结果,成功携带 Data,失败时清空
S_ApiResult<T> 给 Swagger / 前端展示的统一 API 返回体(Code / Message / Data)
DataPageResult<T> / ServicePageResult<T> / Pager<T> 分页返回模型(数据层 / 业务层 / 前端三种语义)
EncEnvelopeV1 v1 加密信封(前后端通用 DTO,承载 SM4-GCM 的 kid/ts/nonce/iv/data/tag)
ApiCatalogResponse API 目录扫描的输出根对象,与 GJJ.Keystone.AspNetCore 的扫描器配套

常量(Contracts/)

  • ApiResultCodeConst:SUCCESS = 1 / ERROR = -1 / FAIL = 0 等标准结果码。
  • ApiResultMessageConst:SUCCESS = "成功" / FAIL = "失败" 标准消息文案。

业务代码(BusinessCodes/)

  • 汇总个人、单位、规则、综服和渠道服务跨系统共用的业务代码,统一使用 GJJ.Keystone.Abstractions.BusinessCodes 命名空间。
  • BusinessTypeConst 是业务类型统一入口;SJZTBusinessSubTypeConst 的值直接保存 API 路由,不再保存需要二次转换的数字键。
  • DrawStatus 与 DWJCBLTZStatusConst 分别表示个人提取和单位缴存比例调整流程,数值相同也不能混用。

领域基元(Domain/Primitives/)

  • JwtClaimTypes:JWT 标准声明常量(sub / name / role / env / dbpoint / channel / user_type / jti 等),在 Token 颁发(Toolkit)与 Claim 读取(AspNetCore)之间共用同一份字符串约定,避免漂移。
  • Enums:领域层枚举占位,集中放置嵌套枚举。

注解(Annotations/)

特性 用途
[EnableAESEncryption] 标记 Controller / Action 需要 AES 参数加解密
[EnableSMEncryption] 标记 Controller / Action 需要 SM4 参数加解密
[EnableApiRegister] 标记 Controller / Action 需要进 API 目录扫描,可附 ChineseName / Description / Group 等元数据
[SkipApplicationIdValidation] 标记跳过 ApplicationId 校验中间件

服务发现抽象(ServiceDiscovery/)

类型 用途
IServiceRegistryClient 服务注册客户端抽象,业务启动入口只表达“注册服务实例”,不暴露 Consul / Nacos SDK 类型
IServiceDiscoveryClient 服务发现客户端抽象,网关等消费方只读取健康实例列表
IServiceRegistryAdmin 服务注册管理抽象,综服后台服务注册管理页通过它查询、启停实例
ServiceRegistration / ServiceInstanceInfo / ServiceInfo 注册参数、实例信息与服务聚合信息的中立 DTO

这些接口的 Nacos/TongNCS 实现位于 GJJ.Keystone.AspNetCore。业务 Application 层若只需要抽象,应直接引用本包,避免为了拿接口把 ASP.NET Core 实现包或 Nacos SDK 拉进来。

登录验证码抽象(Security/Captcha/)

ILoginCaptchaService、LoginCaptchaChallenge 和 LoginCaptchaVerifyStatus 定义跨层登录验证码契约;SVG 生成及 Redis 一次性消费实现在 GJJ.Keystone.AspNetCore。详见登录图形验证码统一规范。

典型用法

在 Application 层返回业务结果

using GJJ.Keystone.Abstractions.Contracts;

public CommandResult<int> AddUser(string name)
{
    if (string.IsNullOrWhiteSpace(name))
        return new CommandResult<int>().Fail("姓名不能为空");

    var newId = _repo.Insert(name);
    return new CommandResult<int>().SetId(newId).Success();
}

public QueryResult<UserDto> GetById(int id)
{
    var user = _repo.Find(id);
    return user is null
        ? new QueryResult<UserDto>().Fail("用户不存在")
        : new QueryResult<UserDto>().Success(user);
}

在 Controller 上声明加密 / 注册

using GJJ.Keystone.Abstractions.Annotations;

[ApiController]
[Route("api/[controller]")]
[EnableSMEncryption]
public class UserController : ControllerBase
{
    [HttpGet("{id}")]
    [EnableApiRegister(ChineseName = "查询用户", Group = "用户管理")]
    public Task<S_ApiResult<UserVM>> Get(int id) { /* ... */ }
}

设计约束

  • 零运行时依赖:除 .NET 8 BCL 外不引入任何第三方包,避免影响调用方版本图。
  • 无副作用:所有类型只承载数据 / 常量 / 元数据 / 接口合同,禁止包含业务逻辑、IO、反射扫描等行为;这类能力放到 Toolkit 或 AspNetCore。
  • 接口稳定优先:契约一旦发布尽量不破坏;如确需变更,遵循语义化版本,旧字段标 [Obsolete] 后再移除。

已知限制

  • DataPageResult<T> 已标记为废弃,请新代码使用 QueryResult<PageData<T>> 或 ServicePageResult<T>。
  • 注解仅是元数据标记,真正的执行逻辑由 GJJ.Keystone.AspNetCore(中间件 / ActionFilter / API 目录扫描器)承担——单独引用本包不会自动启用加密或注册。
Product 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. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
  • net8.0

    • No dependencies.

NuGet packages (8)

Showing the top 5 NuGet packages that depend on GJJ.Keystone.Abstractions:

Package Downloads
GJJ.Keystone.Toolkit

GJJ 微服务公共核心库(国密/通用工具/Excel/反射注册等)

GJJ.Keystone.AspNetCore

GJJ 微服务 ASP.NET Core 扩展(Nacos/TongNCS/OTel/中间件/过滤器/JWT等)

GJJ.Keystone.AspNetCore.KvStore

GJJ Keystone KvStore:通用 KV / 计数器 / 配置加载抽象的 Redis 实现 + Resilient 降级 + Memory 兜底。兼容 TongRDS(Redis 协议)。替代原 Consul KV 与 .Redis 包的安全态 Store。

GJJ.Keystone.Worker

GJJ Keystone Worker 基础设施:面向 Generic Host / Worker Service 的 Nacos 配置中心、观测、日志、启动诊断、可选服务发现与健康端口。

GJJ.Keystone.AspNetCore.Redis

[DEPRECATED] 本包已弃用,请改用 GJJ.Keystone.AspNetCore.KvStore。原职责:INonceStore / IJtiBlacklistStore / ISmSessionKeyStore 的 Redis 实现 + jti 双层缓存(L1 + Redis + Pub/Sub)

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
4.6.1 58 11/23/2026
4.6.0 155 11/4/2026
4.5.4 228 10/19/2026
4.5.3 285 9/24/2026
4.5.2 126 9/24/2026
4.5.1 131 9/23/2026
4.5.0 128 9/17/2026
4.4.9 125 9/16/2026
4.4.8 123 9/16/2026
4.4.7 188 9/4/2026
4.4.6 137 8/25/2026
4.4.5 256 8/19/2026
4.4.4 141 8/13/2026
4.4.3 174 8/12/2026
4.4.2 156 8/11/2026
4.4.1 197 8/7/2026
4.4.0 158 8/6/2026
4.3.0 153 7/28/2026
4.2.3 395 6/30/2026
4.2.2 157 6/26/2026
Loading failed