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" />
                    
Directory.Packages.props
<PackageReference Include="SyZero" />
                    
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 --version 1.1.4
                    
#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
                    
Install as a Cake Addin
#tool nuget:?package=SyZero&version=1.1.4
                    
Install as a Cake Tool

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);
    }
}

⚠️ 注意事项

  1. 配置文件 - 确保 appsettings.json 中包含必要的配置节点
  2. 依赖注入 - 所有服务都应通过依赖注入获取
  3. 异步方法 - 推荐使用异步方法以提高性能

📄 许可证

MIT License - 详见 LICENSE

Product 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.

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.