SyZero.Core
10.0.0
dotnet add package SyZero.Core --version 10.0.0
NuGet\Install-Package SyZero.Core -Version 10.0.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.Core" Version="10.0.0" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="SyZero.Core" Version="10.0.0" />
<PackageReference Include="SyZero.Core" />
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.Core --version 10.0.0
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
#r "nuget: SyZero.Core, 10.0.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.Core@10.0.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.Core&version=10.0.0
#tool nuget:?package=SyZero.Core&version=10.0.0
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
SyZero.Core
SyZero.Core 是一个轻量级的 .NET 微服务框架核心库,提供依赖注入、基础领域模型、服务管理和轻量级事件总线等通用能力。
📦 安装
dotnet add package SyZero.Core
✨ 特性
- 🚀 依赖注入 - 基于
Microsoft.Extensions.DependencyInjection的约定注册 - 🧩 应用基础设施 -
SyZeroServiceBase、ApplicationService、会话与权限基础能力 - 💾 仓储与工作单元接口 - 统一抽象,方便接入 EF Core、SqlSugar、MongoDB
- 🌐 轻量级服务管理 - 内置
LocalServiceManagement、DBServiceManagement - 📣 轻量级事件总线 - 内置
LocalEventBus、DBEventBus - 🛰 远程服务调用抽象 -
IRemoteServiceProvider/IRemoteServiceProxyFactory/RemoteServiceOptions,由SyZero.Feign等模块提供具体 Provider 实现,未来可平行新增更多 Provider
💡 v9.1.0 起,原本位于本包的网关抽象(
IGateway/IGatewayConfigurationStore/GatewayConfiguration等)已迁移到独立包SyZero.Gateway.Abstractions,请按需引用。
- 🧬 动态 API Provider 抽象 -
SyZero.Application.DynamicApi.*:DynamicApiTypeFilter/DynamicApiNameNormalizer/DynamicApiAttributeCache/DynamicApiAssemblyScanner/DynamicApiOptionsBase等公共能力,被SyZero.DynamicWebApi与SyZero.DynamicGrpc共用,方便后续平行新增 Provider - �🔧 配置与工具 - 统一配置读取、异常模型、常用扩展工具
🚀 快速开始
1. 注册核心服务
using SyZero;
var builder = WebApplication.CreateBuilder(args);
builder.AddSyZero();
builder.Services.AddControllers();
var app = builder.Build();
app.UseSyZero();
app.MapControllers();
app.Run();
2. 使用约定注入
using SyZero.Dependency;
public interface IUserService
{
Task<string> GetNameAsync(long id);
}
public class UserService : IUserService, IScopedDependency
{
public Task<string> GetNameAsync(long id)
{
return Task.FromResult($"user-{id}");
}
}
3. 继承应用服务基类
using SyZero.Application.Service;
public class UserAppService : ApplicationService
{
public string GetCurrentUser()
{
return SySession.UserName ?? "anonymous";
}
}
📖 轻量级服务管理
SyZero 核心包内置两种无需额外中间件的服务管理实现:
| 实现 | 场景 | 特点 |
|---|---|---|
LocalServiceManagement |
单机 / 开发环境 | 基于本地文件,无外部依赖 |
DBServiceManagement |
简单多实例部署 | 基于数据库,支持健康检查和 Leader 选举 |
示例:
builder.Services.AddLocalServiceManagement(options =>
{
options.EnableHealthCheck = true;
options.EnableLeaderElection = false;
}, builder.Configuration);
📖 轻量级事件总线
SyZero 核心包内置两种事件总线实现:
| 实现 | 场景 | 特点 |
|---|---|---|
LocalEventBus |
进程内事件 | 基于内存,适合单体应用 |
DBEventBus |
需要持久化与重试 | 基于数据库,适合简单分布式场景 |
示例:
using SyZero.EventBus;
builder.Services.AddLocalEventBus(builder.Configuration);
public class OrderCreatedEvent : EventBase
{
public long OrderId { get; set; }
}
public class OrderCreatedHandler : IEventHandler<OrderCreatedEvent>
{
public Task HandleAsync(OrderCreatedEvent @event)
{
Console.WriteLine($"order created: {@event.OrderId}");
return Task.CompletedTask;
}
}
发布事件:
public class OrderService
{
private readonly IEventBus _eventBus;
public OrderService(IEventBus eventBus)
{
_eventBus = eventBus;
_eventBus.Subscribe<OrderCreatedEvent, OrderCreatedHandler>(() => new OrderCreatedHandler());
}
public Task CreateAsync(long orderId)
{
return _eventBus.PublishAsync(new OrderCreatedEvent
{
OrderId = orderId
});
}
}
⚠️ 说明
builder.AddSyZero()会注册核心依赖,并在app.UseSyZero()时初始化全局运行时。ISySession是请求作用域对象,应只在请求链路内访问。- 轻量级事件总线和服务管理适合简单场景;需要更强可靠性时,建议使用
SyZero.EventBus.RabbitMQ、SyZero.Redis、SyZero.ServiceDiscovery.Consul、SyZero.ServiceDiscovery.Nacos等模块。
📄 许可证
MIT License - 详见 LICENSE
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net10.0 is compatible. 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.
-
net10.0
- Castle.Core (>= 5.2.1)
- Dynamitey (>= 2.0.10.189)
- ImpromptuInterface (>= 7.0.1)
- Microsoft.Extensions.Caching.Abstractions (>= 10.0.13)
- Microsoft.Extensions.Caching.Memory (>= 10.0.13)
- Microsoft.Extensions.Configuration (>= 10.0.13)
- Microsoft.Extensions.Configuration.EnvironmentVariables (>= 10.0.13)
- Microsoft.Extensions.Configuration.Json (>= 10.0.13)
- Microsoft.Extensions.DependencyInjection (>= 10.0.13)
- Microsoft.Extensions.DependencyModel (>= 10.0.13)
- Microsoft.Extensions.Hosting.Abstractions (>= 10.0.13)
- Microsoft.Extensions.Logging.Abstractions (>= 10.0.13)
- Microsoft.Extensions.Options.ConfigurationExtensions (>= 10.0.13)
- Refit (>= 8.0.0)
- Snowflake.Core (>= 2.0.0)
- System.Linq.Dynamic.Core (>= 1.6.6)
NuGet packages (43)
Showing the top 5 NuGet packages that depend on SyZero.Core:
| Package | Downloads |
|---|---|
|
SyZero.Web.Common
SyZero-Web-Common |
|
|
SyZero.EntityFrameworkCore
SyZero-EntityFrameworkCore |
|
|
SyZero.Redis
SyZero-Redis |
|
|
SyZero.AspNetCore
SyZero中的Web层扩展 |
|
|
SyZero.DynamicWebApi
SyZero-DynamicWebApi |
GitHub repositories
This package is not used by any popular GitHub repositories.
| Version | Downloads | Last Updated |
|---|---|---|
| 10.0.0 | 0 | 10/23/2026 |
| 9.1.0 | 52 | 10/22/2026 |
| 1.2.0 | 40 | 10/22/2026 |
| 1.2.0-dev.1 | 36 | 10/22/2026 |