GJJ.Keystone.Abstractions 4.2.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.2.0
                    
NuGet\Install-Package GJJ.Keystone.Abstractions -Version 4.2.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.2.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.2.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.2.0
                    
#r "nuget: GJJ.Keystone.Abstractions, 4.2.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.2.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.2.0
                    
Install as a Cake Addin
#tool nuget:?package=GJJ.Keystone.Abstractions&version=4.2.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/

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

领域基元(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 拉进来。

典型用法

在 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、反射扫描等行为;这类能力放到 ToolkitAspNetCore
  • 接口稳定优先:契约一旦发布尽量不破坏;如确需变更,遵循语义化版本,旧字段标 [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 (5)

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.Redis

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

GJJ.Keystone.AspNetCore.KvStore

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

GJJ.Keystone.AspNetCore.Messaging

GJJ Keystone Messaging:基于 TongHTP Adapter(HTTP REST)的消息收发封装。业务微服务注入 IMessageProducer / IMessageHandler 即可完成发送与订阅,无需感知 Java 中间层。

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
4.2.2 42 6/26/2026
4.2.1 131 6/22/2026
4.2.0 277 6/5/2026
4.1.0 167 5/27/2026
4.0.0 160 5/22/2026
3.0.11 153 5/19/2026
3.0.10 188 5/13/2026
3.0.9 144 5/11/2026
3.0.8 138 5/11/2026
3.0.7 144 5/8/2026
3.0.6 124 5/6/2026
3.0.5 138 5/6/2026
3.0.4 147 5/6/2026
3.0.3 136 4/30/2026
3.0.2 146 4/30/2026
3.0.0 125 4/29/2026
2.0.3 133 4/13/2026
2.0.2 127 4/9/2026
2.0.1 121 4/8/2026
2.0.0 128 4/8/2026
Loading failed