SyZero.DynamicWebApi
1.1.5-dev.1
This is a prerelease version of SyZero.DynamicWebApi.
dotnet add package SyZero.DynamicWebApi --version 1.1.5-dev.1
NuGet\Install-Package SyZero.DynamicWebApi -Version 1.1.5-dev.1
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.5-dev.1" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="SyZero.DynamicWebApi" Version="1.1.5-dev.1" />
<PackageReference Include="SyZero.DynamicWebApi" />
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.5-dev.1
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
#r "nuget: SyZero.DynamicWebApi, 1.1.5-dev.1"
#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.5-dev.1
#: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.5-dev.1&prerelease
#tool nuget:?package=SyZero.DynamicWebApi&version=1.1.5-dev.1&prerelease
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
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
}
⚠️ 注意事项
- 接口定义 - 服务必须实现 IApplicationService 接口
- 命名约定 - 遵循命名约定以正确映射 HTTP 方法
- 特性覆盖 - 可以使用特性覆盖自动生成的路由
📄 许可证
MIT License - 详见 LICENSE
| 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. |
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
-
net9.0
- SyZero (>= 1.1.5-dev.1)
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 | 28 | 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 | 163 | 11/3/2023 |
| 1.1.3-dev.1 | 193 | 3/21/2023 |
| 1.1.2 | 373 | 3/15/2023 |
| 1.1.2-dev.108.29344 | 182 | 3/15/2023 |
| 1.1.2-dev.108.28054 | 195 | 3/15/2023 |
| 1.1.2-dev.108.27487 | 181 | 3/15/2023 |
| 1.1.1 | 316 | 3/15/2023 |
| 1.1.1-dev.108.14980 | 180 | 3/15/2023 |
| 1.1.1-dev.108.13289 | 176 | 3/15/2023 |
| 1.1.1-dev.107.27144 | 180 | 3/14/2023 |
| 1.1.0 | 308 | 3/14/2023 |
| 1.1.0-workflow-dev.107.22552 | 175 | 3/14/2023 |
| 1.1.0-workflow-dev.107.21746 | 179 | 3/14/2023 |
| 1.1.0-workflow-dev.107.21506 | 176 | 3/14/2023 |
| 1.1.0-workflow-dev.107.20979 | 181 | 3/14/2023 |
| 1.1.0-dev.107.26364 | 180 | 3/14/2023 |
| 1.1.0-dev.107.24396 | 186 | 3/14/2023 |
| 1.1.0-dev.107.22787 | 186 | 3/14/2023 |
| 1.0.6 | 575 | 3/5/2022 |
| 1.0.1 | 884 | 2/20/2020 |