SyZero.DynamicGrpc
1.1.5-dev.1
This is a prerelease version of SyZero.DynamicGrpc.
dotnet add package SyZero.DynamicGrpc --version 1.1.5-dev.1
NuGet\Install-Package SyZero.DynamicGrpc -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.DynamicGrpc" 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.DynamicGrpc" Version="1.1.5-dev.1" />
<PackageReference Include="SyZero.DynamicGrpc" />
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.DynamicGrpc --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.DynamicGrpc, 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.DynamicGrpc@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.DynamicGrpc&version=1.1.5-dev.1&prerelease
#tool nuget:?package=SyZero.DynamicGrpc&version=1.1.5-dev.1&prerelease
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
SyZero.DynamicGrpc
SyZero 框架的动态 gRPC 模块,支持自动生成 gRPC 服务。
📦 安装
dotnet add package SyZero.DynamicGrpc
✨ 特性
- 🚀 动态生成 - 根据应用服务自动生成 gRPC 服务
- 💾 无需 Proto - 无需手动编写 .proto 文件
- 🔒 类型安全 - 保持完整的类型检查
🚀 快速开始
1. 配置 appsettings.json
{
"DynamicGrpc": {
"EnableReflection": true
}
}
2. 注册服务
// Program.cs
var builder = WebApplication.CreateBuilder(args);
// 添加SyZero
builder.AddSyZero();
// 注册服务方式1 - 使用默认配置
builder.Services.AddDynamicGrpc();
// 注册服务方式2 - 使用委托配置
builder.Services.AddDynamicGrpc(options =>
{
options.EnableReflection = true;
});
// 注册服务方式3 - 指定服务程序集
builder.Services.AddDynamicGrpc(typeof(UserAppService).Assembly);
var app = builder.Build();
// 使用SyZero
app.UseSyZero();
// 映射 gRPC 服务
app.MapDynamicGrpcService();
app.Run();
3. 使用示例
public interface IUserAppService : IApplicationService
{
Task<UserDto> GetUserAsync(long id);
Task<List<UserDto>> GetUsersAsync();
}
public class UserAppService : IUserAppService
{
public async Task<UserDto> GetUserAsync(long id)
{
// 实现逻辑
}
public async Task<List<UserDto>> GetUsersAsync()
{
// 实现逻辑
}
}
📖 配置选项
| 属性 | 类型 | 默认值 | 说明 |
|---|---|---|---|
EnableReflection |
bool |
true |
启用 gRPC 反射 |
📖 API 说明
IApplicationService 接口
| 方法 | 说明 |
|---|---|
| 继承此接口的服务方法 | 自动暴露为 gRPC 方法 |
所有公开方法都会自动生成对应的 gRPC 服务方法
🔧 高级用法
自定义序列化
builder.Services.AddDynamicGrpc(options =>
{
options.Serializer = new CustomSerializer();
});
gRPC 客户端调用
var channel = GrpcChannel.ForAddress("http://localhost:5000");
var client = channel.CreateGrpcService<IUserAppService>();
var user = await client.GetUserAsync(1);
⚠️ 注意事项
- 接口定义 - 服务必须实现 IApplicationService 接口
- 返回类型 - 方法返回类型必须是可序列化的
- HTTP/2 - gRPC 需要 HTTP/2 支持
📄 许可证
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
- Grpc.AspNetCore (>= 2.76.0)
- protobuf-net.Grpc.AspNetCore (>= 1.2.2)
- 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 | 23 | 1/29/2026 |
| 1.1.4 | 80 | 1/2/2026 |
| 1.1.4-dev.2 | 40 | 1/2/2026 |
| 1.1.4-dev.1 | 39 | 12/30/2025 |
| 1.1.3 | 83 | 12/30/2025 |
| 1.1.3-dev.6 | 41 | 12/30/2025 |