SyZero.Gateway.Abstractions 9.1.0

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

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 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. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

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