HZY.Framework.Repository.EntityFramework.Sqlite 10.1.17

dotnet add package HZY.Framework.Repository.EntityFramework.Sqlite --version 10.1.17
                    
NuGet\Install-Package HZY.Framework.Repository.EntityFramework.Sqlite -Version 10.1.17
                    
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.Repository.EntityFramework.Sqlite" Version="10.1.17" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="HZY.Framework.Repository.EntityFramework.Sqlite" Version="10.1.17" />
                    
Directory.Packages.props
<PackageReference Include="HZY.Framework.Repository.EntityFramework.Sqlite" />
                    
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.Repository.EntityFramework.Sqlite --version 10.1.17
                    
#r "nuget: HZY.Framework.Repository.EntityFramework.Sqlite, 10.1.17"
                    
#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.Repository.EntityFramework.Sqlite@10.1.17
                    
#: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.Repository.EntityFramework.Sqlite&version=10.1.17
                    
Install as a Cake Addin
#tool nuget:?package=HZY.Framework.Repository.EntityFramework.Sqlite&version=10.1.17
                    
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 (1)

Showing the top 1 NuGet packages that depend on HZY.Framework.Repository.EntityFramework.Sqlite:

Package Downloads
HZY.Framework.Repository.EntityFramework.All

HZY.Framework EF Core 仓储 - 全部数据库 Provider 聚合包 元包,引用所有数据库 Provider 包,供不想改引用的下游项目使用。 包含:SqlServer、MySql、PostgreSql、Oracle、Sqlite ===== 使用教程 ===== 安装本包后,按目标数据库选择对应的注册扩展方法(用法与单个 Provider 包一致): builder.AddSqlServerRepository<AppDbContext>(...); // SqlServer builder.AddMySqlRepository<AppDbContext>(...); // MySql builder.AddPostgreSqlRepository<AppDbContext>(...); // PostgreSql builder.AddOracleRepository<AppDbContext>(...); // Oracle builder.AddSqliteRepository<AppDbContext>(...); // Sqlite var app = builder.Build(); app.UseRepository(); 实体特性([TableId] 雪花主键、[TableLogic] 软删除、[TableField] 审计填充) 与仓储用法见 HZY.Framework.Repository.EntityFramework 包说明。 源码与完整文档:https://gitee.com/hzy6/HZY.Framework

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
10.1.17 0 8/18/2026
10.1.16 0 8/18/2026
10.1.15 46 8/13/2026
10.1.14 40 8/13/2026
10.1.10 84 8/6/2026
10.1.9 88 8/5/2026
10.1.8 95 8/3/2026
10.1.7 96 8/3/2026
10.1.6 94 8/3/2026
10.1.5 98 8/3/2026
10.1.4 92 8/3/2026
10.1.3 95 8/3/2026
10.1.2 92 8/3/2026
10.1.1 97 8/3/2026