Lesphere.Framework.AspNetCore 2.0.0

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

Lesphere Framework · 乐枢后端框架

适用于 .NET 10 的模块化后端公共库。业务服务按需选用,各包不依赖药店、平台或桌面项目。

包 职责
Lesphere.Framework.Core 公共异常与错误码、身份与密码规则、查询条件与分页、依赖注入、序列化、校验和基础扩展
Lesphere.Framework.DatabaseAccessor SqlSugar 仓储与连接选择、单连接事务、SQLite 维护基础、宿主实体元数据扩展
Lesphere.Framework.AspNetCore 统一结果与全局异常、可信请求身份、网关上下文、健康探针与 HTTP 管道

三个模块使用同一版本。DatabaseAccessor、AspNetCore 自动依赖 Core;仅使用基础工具时只需安装 Core。

dotnet add package Lesphere.Framework.Core --version 2.0.0
# 按需添加数据库或 Web 管道模块
dotnet add package Lesphere.Framework.DatabaseAccessor --version 2.0.0
dotnet add package Lesphere.Framework.AspNetCore --version 2.0.0

从 1.0.0 升级到 2.0.0

  • 三个包统一升级到 2.0.0,并重新编译使用它们的项目。本次新增了接口成员,不能直接用新 DLL 替换旧程序集。
  • 自定义 IUnitOfWork 实现需要补充 IsolationLevel、IsRollbackOnly 和 SetRollbackOnly();自定义 IUnitOfWorkManager 实现需要补充 Current 及带隔离级别参数的两个重载。仅使用内置实现的项目无需自行实现这些成员。
  • 完整数据访问注册使用 AddDataAccessInfrastructure;已有 SqlSugar 客户端时使用 AddRepositoryInfrastructure。通过 UseSqlSugar 选择当前提供程序。
  • [Transactional] 需要配合 AddTransactionalService<IService, Service>() 和接口调用;只写注解不会自动开启事务。全局及单次事务隔离级别的用法见下方入口说明。
  • 受管理的嵌套事务共享提交边界,内层失败会标记整笔事务必须回滚;外部直接开启的 ADO 事务不支持框架提交回调。

接入边界

  • 公共异常位于 Lesphere.Framework.Exceptions;全局管道将业务失败映射为 HTTP 200 和 success=false,认证、授权与基础设施故障保留实际 HTTP 状态。
  • SqlSugarUnitOfWorkManager 管理单个数据库连接。跨服务操作通过 API 协调,不支持跨库原子事务。
  • 业务表、实体约束和租户隔离策略由宿主维护,可通过 IDatabaseSchemaMetadataProvider 提供实体唯一约束。
  • 应用启动不会自动创建、升级或备份数据库;结构维护需要显式调用维护能力。
  • 数据访问包当前验证的数据库为 SQLite;枚举中的其他提供方不代表已包含对应驱动或完成适配验证。
  • 桌面打印、本机传输、设备凭据不属于本框架。

公共规则示例

using Lesphere.Framework.Exceptions;
using Lesphere.Framework.Security;

// 密码校验只返回结论,不持有或记录密码原文。
var result = PasswordPolicy.Evaluate(password, userName);
if (!result.IsValid)
    throw new BusinessException(result.ErrorMessage!);

库通过 XML 文档提供类型与方法说明。运行环境为 .NET 10;Web 模块还需要 ASP.NET Core 共享运行时。

仅使用 SQLite 的应用

SqlSugarCoreNoDrive 5.1.4.221 的上游 SystemCommon 8.5.0 元包仍声明 SQL Server 相关传递依赖。公共包保留上游依赖声明,不暗中改写消费方的还原策略。仅部署 SQLite 时,在应用自身的项目文件或 Directory.Packages.props 中添加:

<ItemGroup>
  
  <PrunePackageReference Include="SystemCommon" Version="8.5.0" />
</ItemGroup>

然后执行 dotnet restore。此规则只针对已核验版本;升级 SqlSugar 后应重新验证。普通安装和采用此 SQLite 裁剪配置的安装均有独立消费端验证。框架源码所在工作区已配置相同规则。

依赖注入与数据访问入口

  • AddMarkedServices 只扫描指定程序集;支持生命周期标记及 ServiceRegistration 显式契约、顺序、服务键。闭合泛型接口可自动登记,开放泛型使用原生容器显式登记。
  • AddServiceTypes 可精确指定实现;批次校验失败不会写入部分注册。SkipServiceRegistration 可排除自动扫描。
  • AddDataAccessInfrastructure(database => database.UseSqlSugar(factory)) 登记客户端、仓储和单库工作单元;已有连接工厂使用 AddRepositoryInfrastructure(database => database.UseSqlSugar())。入口与 ORM 提供程序分离,客户端由作用域释放。
  • ConfigureTransactions / DatabaseTransactionOptions 配置全局隔离级别,单次开启或 [Transactional(IsolationLevel = ...)] 可覆盖;Unspecified 使用驱动默认,加入已有事务时继承外层。
  • AddTransactionalService<IService, Service>() 启用接口上的声明式事务:异步完成后提交,异常或取消回滚,内层失败被捕获也不能部分提交。需要接口调用,当前支持 Required 单库传播,不支持 NativeAOT。
  • IDataAccessProvider 为其他 ORM 预留组装入口;现有仓储查询 API 仍依赖 SqlSugar,当前未提供其他 ORM 的适配器。
  • 连接方言必须显式配置,CQRSEnabled 决定是否使用读副本。创建配置不会连接、建库或迁移;宿主负责租户授权和查询过滤。
  • 同一工作单元管理器内的借用事务回调转交外层,在真正提交后执行;借用未受管理的外部 ADO 事务时拒绝登记回调。跨服务不使用跨库事务。
  • ToPagedList/ToPagedListAsync 页码从 1 开始,每页 1~1000 条,拒绝溢出偏移;批量导出使用分批或流式查询。
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

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
3.0.0 86 11/16/2026
2.0.0 112 10/4/2026
1.0.0 105 10/1/2026

增强依赖注入与数据访问注册;新增全局及单次事务隔离级别、接口代理声明式事务和回滚标记。工作单元接口已扩展,自定义实现升级时需要适配,详见包内 README。