HZY.Framework.Core 10.1.16

There is a newer version of this package available.
See the version list below for details.
dotnet add package HZY.Framework.Core --version 10.1.16
                    
NuGet\Install-Package HZY.Framework.Core -Version 10.1.16
                    
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="HZY.Framework.Core" Version="10.1.16" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="HZY.Framework.Core" Version="10.1.16" />
                    
Directory.Packages.props
<PackageReference Include="HZY.Framework.Core" />
                    
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 HZY.Framework.Core --version 10.1.16
                    
#r "nuget: HZY.Framework.Core, 10.1.16"
                    
#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 HZY.Framework.Core@10.1.16
                    
#: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=HZY.Framework.Core&version=10.1.16
                    
Install as a Cake Addin
#tool nuget:?package=HZY.Framework.Core&version=10.1.16
                    
Install as a Cake Tool

HZY.Framework

模块化 .NET 10 插件框架:AOP、依赖注入、EF Core 仓储、动态 API 控制器、定时任务、Redis、服务器监控。

包清单

说明
HZY.Framework.Aop AOP 拦截器基类(Rougamo 编译期静态织入,无动态代理、无性能损耗)
HZY.Framework.Core 核心主干:AOP、DI 特性注册、启动模块、定时任务、Redis、服务器指标监控
HZY.Framework.Repository.EntityFramework EF Core 泛型仓储:软删除、审计字段、雪花 ID、分表、字段加密、事务、批量操作
HZY.Framework.Repository.EntityFramework.{SqlServer/MySql/PostgreSql/Oracle/Sqlite} 数据库 Provider(按需选装)
HZY.Framework.Repository.EntityFramework.All 全部数据库 Provider 聚合包
HZY.Framework.DynamicApiController 服务类自动映射为 HTTP API 控制器

快速开始

// 1. 定义启动模块(可组合多个模块,按 Order 排序执行)
[ImportStartupModule(typeof(RepositoryStartupModule))]
public class AppStartup : StartupModule<AppStartup>
{
    public override void ConfigureServices(WebApplicationBuilder builder)
    {
        // 动态 API 控制器:实现 IDynamicApiController 的服务自动注册为控制器
        builder.Services.AddControllers().AddDynamicApiController();

        // 扫描 [Component] 特性自动注册服务
        builder.Services.AddDependencyInjectionByComponent([typeof(Program).Assembly]);
    }
}

// 2. Program.cs —— 一行启动
var builder = WebApplication.CreateSlimBuilder(args);
HzyApplication.Run<AppStartup>(builder);

功能速查(AI 友好索引)

依赖注入

[Component]                                              // 默认 Transient
[Component(ServiceLifetime.Scoped)]                      // 指定生命周期
[Component(typeof(IUserService), ServiceLifetime.Singleton)] // 指定接口注册
public class UserService : IUserService { }

public class OrderService
{
    [Autowired]                                          // 属性注入(AOP 拦截 get)
    public IUserService UserService { get; set; } = null!;
}

注册入口:services.AddDependencyInjectionByComponent([typeof(Program).Assembly])

AOP 拦截器

自定义拦截器继承 AopMoAttribute(基于 Rougamo.Fody 编译期织入,零运行时代理):

public class LogAttribute : AopMoAttribute
{
    public override void OnEntry(MethodContext context) { /* 方法进入 */ }
    public override void OnSuccess(MethodContext context) { /* 方法成功 */ }
    public override void OnException(MethodContext context) { /* 方法异常 */ }
    public override void OnExit(MethodContext context) { /* 方法退出(重写时必须调 base) */ }
}

// 内置拦截器
[Time]                                                   // 记录方法耗时日志
[MemoryCache(CacheKey = "user:{id}", CacheDuration = 60)] // 内存缓存(秒,0=永久)

EF Core 仓储

// 注册(MySql 为例,其他数据库换对应 Provider 包)
builder.AddRepository<AppDbContext>(new RepositoryOptions
{
    DefaultDatabaseType = DefaultDatabaseType.MySql,
    ConnectionString = builder.Configuration.GetConnectionString("Default")!
});

// 使用:任意服务构造函数注入 IRepository<T>
public class MemberService(IRepository<Member> memberRepository)
{
    // 查询(软删除自动过滤)
    var page = await memberRepository.Queryable
        .WhereIf(!string.IsNullOrWhiteSpace(keyword), w => w.Name.Contains(keyword))
        .ToPageAsync(1, 20);

    // 增删改(雪花 ID、审计字段自动填充,[Transactional] 事务保护)
    await memberRepository.InsertAsync(entity);
    await memberRepository.UpdateAsync(entity);
    await memberRepository.DeleteByIdAsync(id);          // 软删除:改写为 UPDATE
}

实体特性(标记在属性上即生效,无需配置):

特性 作用
[TableId(IdType.SnowflakeId)] 主键自动生成:雪花 ID / UUID / UUID 字符串
[TableLogic] 软删除:查询自动过滤 + 删除改写为 UPDATE
[TableField(TableFieldFill.CreateTime)] 审计字段自动填充:CreateTime / CreateId / UpdateTime / UpdateId / DeleteTime / DeleteId
[TableName(NameRuleType.SnakeCase)] 表名/字段命名规则(蛇形命名 SysFunction → sys_function)
[Dict("dict_code")] 数据字典映射
[TableFieldEncrypt] 字段透明加解密

方法级特性:

[Transactional]                                          // 事务(支持嵌套复用、多 DbContext)
[Transactional(typeof(AppDbContext), typeof(OtherDbContext))] // 多库事务
public async Task CreateOrderAsync(Order order) { ... }

动态 API 控制器

// 实现该接口(或标记 [DynamicApiController])→ 自动注册为控制器
// 路由 kebab-case,方法名前缀推断 HTTP 方法(Get*/Query*→GET,Add*/Create*→POST,...)
public class MemberAppService : IDynamicApiController
{
    public async Task<List<MemberDto>> GetListAsync(string? keyword) { ... }
    // → GET /member/list?keyword=xxx  (具体规则可配)
}

定时任务

[Component]
public class JobService
{
    [Scheduled("0/5 * * * * ?")]                          // 每 5 秒(Quartz Cron)
    public void SyncData() { ... }
}

全局服务网关

App.Services                  // IServiceCollection
App.ServiceProvider           // IServiceProvider(根容器)
App.HttpContext               // 当前 HttpContext
App.CreateScope()             // 创建服务作用域
App.GetJobTaskInfoList()      // 定时任务信息

更多文档

完整功能说明、数据库 Provider 配置、读写分离、分表、并发控制、服务器监控等,见仓库 README: https://gitee.com/hzy6/HZY.Framework

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

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories (1)

Showing the top 1 popular GitHub repositories that depend on HZY.Framework.Core:

Repository Stars
hzy-6/hzy-admin
前后端分离权限管理系统基架! 数据权限、按钮权限、动态菜单、动态任务调度、动态WebApi、定时标记 [Scheduled("0/5 * * * * ?")] 、代码生成
Version Downloads Last Updated
10.1.17 0 8/18/2026
10.1.16 31 8/18/2026
10.1.15 48 8/13/2026
10.1.14 50 8/13/2026
10.1.10 87 8/6/2026
10.1.9 85 8/5/2026
10.1.8 98 8/3/2026
10.1.7 90 8/3/2026
10.1.6 94 8/3/2026
10.1.5 101 8/3/2026
10.1.4 94 8/3/2026
10.1.3 94 8/3/2026
10.1.2 164 8/3/2026
10.1.1 181 8/3/2026
10.0.13 134 4/4/2026
10.0.12 144 3/18/2026
10.0.11 121 3/1/2026
10.0.9 115 3/1/2026
10.0.8 118 3/1/2026
10.0.7 126 2/23/2026
Loading failed