SyZero 1.1.4
dotnet add package SyZero --version 1.1.4
NuGet\Install-Package SyZero -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" Version="1.1.4" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="SyZero" Version="1.1.4" />
<PackageReference Include="SyZero" />
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 --version 1.1.4
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
#r "nuget: SyZero, 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@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&version=1.1.4
#tool nuget:?package=SyZero&version=1.1.4
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
SyZero
SyZero 是一个轻量级的 .NET 微服务框架核心库,提供依赖注入、配置管理、领域驱动等基础功能。
📦 安装
dotnet add package SyZero
✨ 特性
- 🚀 依赖注入 - 基于 Microsoft.Extensions.DependencyInjection 的模块化依赖注入
- 💾 仓储模式 - 通用仓储接口和工作单元模式
- 🔒 配置管理 - 统一的配置读取和管理
- 🎯 领域驱动 - 实体、值对象、领域事件等 DDD 基础设施
- 📝 异常处理 - 统一的业务异常和友好异常处理
🚀 快速开始
1. 配置 appsettings.json
{
"Server": {
"Name": "MyService",
"Port": 5000
}
}
2. 注册服务
// Program.cs
var builder = WebApplication.CreateBuilder(args);
// 添加SyZero
builder.AddSyZero();
// 注册服务方式1 - 使用配置文件
builder.Services.AddSyZero();
// 注册服务方式2 - 使用委托配置
builder.Services.AddSyZero(options =>
{
options.ServerName = "MyService";
options.ServerPort = 5000;
});
var app = builder.Build();
// 使用SyZero
app.UseSyZero();
app.Run();
3. 使用示例
// 定义实体
public class User : Entity<long>
{
public string Name { get; set; }
public string Email { get; set; }
}
// 使用仓储
public class UserService
{
private readonly IRepository<User, long> _userRepository;
public UserService(IRepository<User, long> userRepository)
{
_userRepository = userRepository;
}
public async Task<User> GetUserAsync(long id)
{
return await _userRepository.GetAsync(id);
}
}
📖 配置选项
| 属性 | 类型 | 默认值 | 说明 |
|---|---|---|---|
ServerName |
string |
"" |
服务名称 |
ServerPort |
int |
5000 |
服务端口 |
📖 API 说明
IRepository<TEntity, TPrimaryKey> 接口
| 方法 | 说明 |
|---|---|
GetAsync(id) |
根据主键获取实体 |
GetListAsync() |
获取实体列表 |
InsertAsync(entity) |
插入实体 |
UpdateAsync(entity) |
更新实体 |
DeleteAsync(id) |
删除实体 |
所有方法都有对应的异步版本(带
Async后缀)
🔧 高级用法
自定义仓储
public interface IUserRepository : IRepository<User, long>
{
Task<User> GetByEmailAsync(string email);
}
public class UserRepository : BaseRepository<User, long>, IUserRepository
{
public async Task<User> GetByEmailAsync(string email)
{
return await GetFirstOrDefaultAsync(u => u.Email == email);
}
}
⚠️ 注意事项
- 配置文件 - 确保 appsettings.json 中包含必要的配置节点
- 依赖注入 - 所有服务都应通过依赖注入获取
- 异步方法 - 推荐使用异步方法以提高性能
📄 许可证
MIT License - 详见 LICENSE
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net5.0 was computed. net5.0-windows was computed. net6.0 was computed. net6.0-android was computed. net6.0-ios was computed. net6.0-maccatalyst was computed. net6.0-macos was computed. net6.0-tvos was computed. net6.0-windows was computed. net7.0 was computed. net7.0-android was computed. net7.0-ios was computed. net7.0-maccatalyst was computed. net7.0-macos was computed. net7.0-tvos was computed. net7.0-windows was computed. net8.0 was computed. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. net9.0 was computed. 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. |
| .NET Core | netcoreapp3.0 was computed. netcoreapp3.1 was computed. |
| .NET Standard | netstandard2.1 is compatible. |
| MonoAndroid | monoandroid was computed. |
| MonoMac | monomac was computed. |
| MonoTouch | monotouch was computed. |
| Tizen | tizen60 was computed. |
| Xamarin.iOS | xamarinios was computed. |
| Xamarin.Mac | xamarinmac was computed. |
| Xamarin.TVOS | xamarintvos was computed. |
| Xamarin.WatchOS | xamarinwatchos was computed. |
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
-
.NETStandard 2.1
- Castle.Core (>= 5.1.1)
- Dynamitey (>= 2.0.10.189)
- ImpromptuInterface (>= 7.0.1)
- Microsoft.Extensions.Caching.Abstractions (>= 9.0.6)
- Microsoft.Extensions.Configuration (>= 9.0.0)
- Microsoft.Extensions.Configuration.EnvironmentVariables (>= 9.0.0)
- Microsoft.Extensions.Configuration.Json (>= 9.0.0)
- Microsoft.Extensions.DependencyInjection (>= 9.0.0)
- Microsoft.Extensions.DependencyModel (>= 9.0.0)
- Microsoft.Extensions.Hosting.Abstractions (>= 9.0.0)
- Microsoft.Extensions.Logging.Abstractions (>= 9.0.0)
- Microsoft.Extensions.Options.ConfigurationExtensions (>= 9.0.0)
- Refit (>= 8.0.0)
- Snowflake.Core (>= 2.0.0)
- System.Linq.Dynamic.Core (>= 1.6.6)
NuGet packages (16)
Showing the top 5 NuGet packages that depend on SyZero:
| Package | Downloads |
|---|---|
|
SyZero.Web.Common
SyZero-Web-Common |
|
|
SyZero.EntityFrameworkCore
SyZero-EntityFrameworkCore |
|
|
SyZero.Log4Net
SyZero-Log4Net |
|
|
SyZero.AutoMapper
SyZero-AutoMapper |
|
|
SyZero.Redis
SyZero-Redis |
GitHub repositories
This package is not used by any popular GitHub repositories.
| Version | Downloads | Last Updated | |
|---|---|---|---|
| 1.1.4 | 517 | 1/2/2026 | |
| 1.1.4-dev.2 | 53 | 1/2/2026 | |
| 1.1.4-dev.1 | 56 | 12/30/2025 | |
| 1.1.3 | 532 | 12/30/2025 | |
| 1.1.3-dev.6 | 65 | 12/30/2025 | |
| 1.1.3-dev.3 | 113 | 1/19/2024 | |
| 1.1.3-dev.2 | 176 | 11/3/2023 | |
| 1.1.3-dev.1 | 197 | 3/21/2023 | |
| 1.1.2 | 2,058 | 3/15/2023 | |
| 1.1.2-dev.108.29344 | 179 | 3/15/2023 | |
| 1.1.2-dev.108.28054 | 184 | 3/15/2023 | |
| 1.1.2-dev.108.27487 | 178 | 3/15/2023 | |
| 1.1.1 | 2,019 | 3/15/2023 | |
| 1.1.1-dev.108.14980 | 181 | 3/15/2023 | |
| 1.1.1-dev.108.13289 | 176 | 3/15/2023 | |
| 1.1.1-dev.107.27144 | 182 | 3/14/2023 | |
| 1.1.0 | 2,054 | 3/14/2023 | |
| 1.1.0-workflow-dev.107.22552 | 255 | 3/14/2023 | |
| 1.1.0-workflow-dev.107.21746 | 251 | 3/14/2023 | |
| 1.1.0-workflow-dev.107.21506 | 256 | 3/14/2023 | |
| 1.1.0-workflow-dev.107.20979 | 250 | 3/14/2023 | |
| 1.1.0-dev.107.26364 | 182 | 3/14/2023 | |
| 1.1.0-dev.107.24396 | 183 | 3/14/2023 | |
| 1.1.0-dev.107.22787 | 180 | 3/14/2023 | |
| 1.0.6 | 2,841 | 3/5/2022 | |
| 1.0.4 | 1,765 | 6/13/2020 | |
| 1.0.3 | 678 | 2/20/2020 | |
| 1.0.2 | 898 | 2/20/2020 | |
| 1.0.1 | 2,461 | 2/20/2020 | |
| 1.0.0 | 1,217 | 11/5/2019 |