SyZero.DynamicWebApi 1.1.4

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

SyZero.DynamicWebApi

SyZero 框架的动态 Web API 模块,支持自动生成 RESTful API。

📦 安装

dotnet add package SyZero.DynamicWebApi

✨ 特性

  • 🚀 动态生成 - 根据应用服务自动生成 Web API
  • 🎯 RESTful - 自动映射为 RESTful 风格
  • 📖 Swagger - 自动生成 API 文档

🚀 快速开始

1. 配置 appsettings.json

{
  "DynamicWebApi": {
    "DefaultAreaName": "api",
    "DefaultHttpVerb": "POST"
  }
}

2. 注册服务

// Program.cs
var builder = WebApplication.CreateBuilder(args);
// 添加SyZero
builder.AddSyZero();

// 注册服务方式1 - 使用默认配置
builder.Services.AddDynamicWebApi();

// 注册服务方式2 - 使用委托配置
builder.Services.AddDynamicWebApi(options =>
{
    options.DefaultAreaName = "api";
    options.DefaultHttpVerb = "POST";
});

// 注册服务方式3 - 指定服务程序集
builder.Services.AddDynamicWebApi(typeof(UserAppService).Assembly);

var app = builder.Build();
// 使用SyZero
app.UseSyZero();
app.MapControllers();
app.Run();

3. 使用示例

public interface IUserAppService : IApplicationService
{
    Task<UserDto> GetAsync(long id);
    Task<UserDto> CreateAsync(CreateUserInput input);
    Task<UserDto> UpdateAsync(long id, UpdateUserInput input);
    Task DeleteAsync(long id);
}

public class UserAppService : IUserAppService
{
    // 实现方法
    // 自动生成:
    // GET    /api/user/{id}
    // POST   /api/user
    // PUT    /api/user/{id}
    // DELETE /api/user/{id}
}

📖 配置选项

属性 类型 默认值 说明
DefaultAreaName string "api" 默认区域名称
DefaultHttpVerb string "POST" 默认 HTTP 方法
RemoveActionPostfixes string[] ["Async"] 移除的方法后缀

📖 API 说明

方法命名约定

方法前缀 HTTP 方法
Get/Find/Fetch/Query GET
Create/Add/Insert POST
Update/Modify/Edit PUT
Delete/Remove DELETE

方法名自动映射为对应的 HTTP 方法


🔧 高级用法

自定义路由

[DynamicWebApi]
[Route("api/v2/[controller]")]
public class UserAppService : IUserAppService
{
    [HttpGet("{id}")]
    public async Task<UserDto> GetAsync(long id)
    {
        // 实现逻辑
    }
}

禁用特定方法

[NonDynamicWebApi]
public async Task InternalMethodAsync()
{
    // 此方法不会暴露为 API
}

⚠️ 注意事项

  1. 接口定义 - 服务必须实现 IApplicationService 接口
  2. 命名约定 - 遵循命名约定以正确映射 HTTP 方法
  3. 特性覆盖 - 可以使用特性覆盖自动生成的路由

📄 许可证

MIT License - 详见 LICENSE

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

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
1.1.5-dev.1 33 1/29/2026
1.1.4 92 1/2/2026
1.1.4-dev.2 46 1/2/2026
1.1.4-dev.1 44 12/30/2025
1.1.3 96 12/30/2025
1.1.3-dev.6 46 12/30/2025
1.1.3-dev.3 104 1/19/2024
1.1.3-dev.2 164 11/3/2023
1.1.3-dev.1 194 3/21/2023
1.1.2 374 3/15/2023
1.1.2-dev.108.29344 183 3/15/2023
1.1.2-dev.108.28054 196 3/15/2023
1.1.2-dev.108.27487 182 3/15/2023
1.1.1 317 3/15/2023
1.1.1-dev.108.14980 181 3/15/2023
1.1.1-dev.108.13289 177 3/15/2023
1.1.1-dev.107.27144 181 3/14/2023
1.1.0 309 3/14/2023
1.1.0-workflow-dev.107.22552 176 3/14/2023
1.1.0-workflow-dev.107.21746 180 3/14/2023
1.1.0-workflow-dev.107.21506 177 3/14/2023
1.1.0-workflow-dev.107.20979 182 3/14/2023
1.1.0-dev.107.26364 181 3/14/2023
1.1.0-dev.107.24396 187 3/14/2023
1.1.0-dev.107.22787 187 3/14/2023
1.0.6 576 3/5/2022
1.0.1 885 2/20/2020