SyZero.Gateway.Abstractions
1.2.0
See the version list below for details.
dotnet add package SyZero.Gateway.Abstractions --version 1.2.0
NuGet\Install-Package SyZero.Gateway.Abstractions -Version 1.2.0
<PackageReference Include="SyZero.Gateway.Abstractions" Version="1.2.0" />
<PackageVersion Include="SyZero.Gateway.Abstractions" Version="1.2.0" />
<PackageReference Include="SyZero.Gateway.Abstractions" />
paket add SyZero.Gateway.Abstractions --version 1.2.0
#r "nuget: SyZero.Gateway.Abstractions, 1.2.0"
#:package SyZero.Gateway.Abstractions@1.2.0
#addin nuget:?package=SyZero.Gateway.Abstractions&version=1.2.0
#tool nuget:?package=SyZero.Gateway.Abstractions&version=1.2.0
SyZero.Gateway.Abstractions
自 v9.1.0 引入的网关抽象层。在此之前,相同抽象(命名空间
SyZero.Gateway)位于SyZero.Core包内;为了让SyZero.Core真正聚焦于框架内核(DI / 仓储 / 服务管理 / 事件总线 / 多级缓存),网关相关抽象被独立成本包。
SyZero.Gateway.Abstractions 只包含接口与 DTO,不引入任何具体网关依赖。所有 SyZero 网关实现(SyZero.Gateway.Ocelot、SyZero.Gateway.YARP)以及管理面板(SyZero.Gateway.Admin)都通过本包共享同一套抽象,从而实现「实现可插拔、面板共用、配置 schema 一致」。
安装
dotnet add package SyZero.Gateway.Abstractions
通常你不会直接引用本包 —— 应当引用一个具体实现(
SyZero.Gateway.Ocelot或SyZero.Gateway.YARP),它们会自动将SyZero.Gateway.Abstractions作为依赖一并引入。只有当你自己实现一个新的IGateway后端时,才需要直接引用本包。
命名空间
整个抽象层位于命名空间 SyZero.Gateway(与包名不同,故意保留以兼容老版本 using SyZero.Gateway;)。
using SyZero.Gateway;
核心抽象
| 抽象 | 用途 | 典型实现 |
|---|---|---|
IGateway |
当前生效的网关运行时(ProviderName + GetConfigurationAsync) |
OcelotGateway、YarpGateway |
IGatewayConfigurationStore |
网关配置持久化(读 / 写 / 重载 / 备份生命周期) | FileGatewayConfigurationStore(SyZero.Gateway.Admin)、OcelotConfigurationStore、YarpConfigurationStore |
IGatewayConfigurationApplier |
把 GatewayConfiguration 热下发到运行中的网关管线 |
OcelotConfigurationApplier、YarpConfigurationApplier |
GatewayConfiguration |
网关顶层配置 DTO(Routes + SwaggerEndPoints + Extra,含全局限流桥) |
— |
GatewayRoute |
单条路由(含 Disabled / Tags / 限流 / 负载均衡) |
— |
GatewaySwaggerEndPoint |
Swagger 聚合端点 | — |
GatewayOptions |
网关公共选项基类(CORS / Swagger 标题 / Service 段读取) | SyZeroOcelotOptions、SyZeroYarpOptions 继承 |
GatewayLoadBalancerOptions / GatewayRateLimitOptions / GatewayGlobalRateLimitOptions |
与 ocelot.json 对齐的 DTO,便于多后端共用同一份 configuration.json |
— |
设计要点
- schema 与 ocelot.json 兼容:所有 DTO 字段命名沿用 PascalCase 习惯,
SyZero.Gateway.Ocelot与SyZero.Gateway.YARP共享同一份configuration.json,实现间可平滑切换。 Extra透传:GatewayConfiguration通过[JsonExtensionData]保留未识别的根级字段(如GlobalConfiguration),保证写回时不丢失。- 可选备份能力:
IGatewayConfigurationStore暴露ListBackupsAsync/ReadBackupAsync/RestoreBackupAsync/DeleteBackupAsync默认接口方法(默认抛NotSupportedException,由SyZero.Gateway.Admin的FileGatewayConfigurationStore提供完整实现)。
自实现一个网关后端
public sealed class MyCustomGateway : IGateway
{
public string ProviderName => "MyCustom";
public Task<GatewayConfiguration> GetConfigurationAsync(CancellationToken ct = default)
{
// 从你的运行时取出当前生效的路由,转换为 GatewayConfiguration 返回
return Task.FromResult(new GatewayConfiguration());
}
}
实现 IGatewayConfigurationStore + IGatewayConfigurationApplier,并在你的扩展方法里注册:
services.AddSingleton<IGateway, MyCustomGateway>();
services.AddSingleton<IGatewayConfigurationStore, MyCustomConfigStore>();
services.AddSingleton<IGatewayConfigurationApplier, MyCustomApplier>();
之后 SyZero.Gateway.Admin 即可直接管理你的自定义网关,无需任何额外适配。
历史
- v9.1.0:从
SyZero.Core抽出,作为独立 NuGet 包发布。命名空间SyZero.Gateway保持不变 —— 业务using无需修改,只需在引用了SyZero.Core的项目里改为引用具体实现包(或本抽象包)。
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net9.0 is compatible. 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. |
-
net9.0
- Microsoft.Extensions.Configuration (>= 9.0.0)
NuGet packages (3)
Showing the top 3 NuGet packages that depend on SyZero.Gateway.Abstractions:
| Package | Downloads |
|---|---|
|
SyZero.Gateway.YARP
SyZero 网关模块的 YARP(Yet Another Reverse Proxy)实现,提供 IGateway / IGatewayConfigurationStore / IGatewayConfigurationApplier 的 YARP 后端,与 SyZero.Gateway.Ocelot 同级互斥。原名 SyZero.YARP,自 v1.6.0 起改名为 SyZero.Gateway.YARP。 |
|
|
SyZero.Gateway.Admin
SyZero 网关的可视化管理面板(Routes / SwaggerEndPoints CRUD),含 Razor Pages UI、Basic Auth、配置读写。仅依赖 SyZero.Gateway.Abstractions 暴露的 IGateway / IGatewayConfigurationStore 抽象,不绑定具体网关实现。 |
|
|
SyZero.Gateway.Ocelot
SyZero 网关模块的 Ocelot 实现,提供 IGateway / IGatewayConfigurationStore / IGatewayConfigurationApplier 的 Ocelot 后端。原名 SyZero.Ocelot,自 v1.6.0 起改名为 SyZero.Gateway.Ocelot 以与抽象包 SyZero.Gateway.Abstractions、面板包 SyZero.Gateway.Admin、YARP 实现包 SyZero.Gateway.YARP 在命名上对齐。 |
GitHub repositories
This package is not used by any popular GitHub repositories.
| Version | Downloads | Last Updated |
|---|---|---|
| 10.0.0 | 148 | 10/23/2026 |
| 9.1.0 | 136 | 10/22/2026 |
| 1.2.0 | 137 | 10/22/2026 |
| 1.2.0-dev.1 | 73 | 10/22/2026 |