Healnet.Core
1.0.7
There is a newer version of this package available.
See the version list below for details.
See the version list below for details.
dotnet add package Healnet.Core --version 1.0.7
NuGet\Install-Package Healnet.Core -Version 1.0.7
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="Healnet.Core" Version="1.0.7" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Healnet.Core" Version="1.0.7" />
<PackageReference Include="Healnet.Core" />
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 Healnet.Core --version 1.0.7
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
#r "nuget: Healnet.Core, 1.0.7"
#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 Healnet.Core@1.0.7
#: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=Healnet.Core&version=1.0.7
#tool nuget:?package=Healnet.Core&version=1.0.7
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
Healnet.Core
Healnet.Core 是 Healnet 框架的核心业务层类库,提供领域层的基础接口和通用服务。
功能特性
| 模块 | 接口 | 说明 |
|---|---|---|
| 仓储接口 | IRepository<TEntity, TKey> |
定义完整的数据访问操作接口(CRUD) |
| 工作单元 | IUnitOfWork |
提供事务管理支持,统一提交/回滚 |
| 服务接口 | IService<TEntity, TKey> |
定义业务服务基类接口 |
| 缓存服务 | ICacheService |
定义缓存操作接口(增删改查) |
| 消息发布/订阅 | IMessagePublisher/IMessageSubscriber |
定义消息队列接口 |
| 统一响应 | ApiResponse<T> |
统一API响应格式封装 |
| 分页响应 | PagedResponse<T> |
分页数据响应封装 |
| 异常处理 | - | 统一业务异常类型(NotFoundException、BusinessException等) |
安装
Install-Package Healnet.Core
使用示例
IRepository
public class UserService
{
private readonly IRepository<User, long> _userRepository;
public UserService(IRepository<User, long> userRepository)
{
_userRepository = userRepository;
}
public async Task<User> CreateUserAsync(UserCreateDto dto)
{
var user = new User
{
Name = dto.Name,
Email = dto.Email,
Password = HashPassword(dto.Password)
};
return await _userRepository.AddAsync(user);
}
public async Task<User> UpdateUserAsync(long id, UserUpdateDto dto)
{
var user = await _userRepository.GetByIdAsync(id);
if (user == null) throw new NotFoundException("User not found");
user.Name = dto.Name;
user.Email = dto.Email;
return await _userRepository.UpdateAsync(user);
}
}
IUnitOfWork
public async Task ProcessOrderAsync(Order order)
{
using var unitOfWork = _unitOfWorkFactory.Create();
try
{
await _orderRepository.AddAsync(order);
await _inventoryRepository.UpdateStockAsync(order.Items);
await unitOfWork.CommitAsync();
}
catch
{
await unitOfWork.RollbackAsync();
throw;
}
}
异常处理
try
{
var user = await _userRepository.GetByIdAsync(userId);
if (user == null)
{
throw new NotFoundException("User not found");
}
if (!user.IsActive)
{
throw new BusinessException("User is inactive");
}
}
catch (NotFoundException ex)
{
// 处理资源未找到异常
}
catch (BusinessException ex)
{
// 处理业务逻辑异常
}
IRepository 接口方法
| 方法 | 说明 | 参数 |
|---|---|---|
GetByIdAsync(TKey id) |
根据ID获取实体 | id: 实体ID |
GetAllAsync() |
获取所有实体 | - |
GetListAsync(Expression<Func<TEntity, bool>> predicate) |
根据条件获取实体列表 | predicate: 查询条件 |
AddAsync(TEntity entity) |
添加实体 | entity: 实体对象 |
AddRangeAsync(IEnumerable<TEntity> entities) |
批量添加实体 | entities: 实体集合 |
UpdateAsync(TEntity entity) |
更新实体 | entity: 实体对象 |
UpdateRangeAsync(IEnumerable<TEntity> entities) |
批量更新实体 | entities: 实体集合 |
DeleteAsync(TKey id) |
根据ID删除实体 | id: 实体ID |
DeleteAsync(TEntity entity) |
删除实体 | entity: 实体对象 |
DeleteRangeAsync(IEnumerable<TEntity> entities) |
批量删除实体 | entities: 实体集合 |
ExistsAsync(Expression<Func<TEntity, bool>> predicate) |
判断是否存在满足条件的实体 | predicate: 查询条件 |
CountAsync(Expression<Func<TEntity, bool>> predicate) |
统计满足条件的实体数量 | predicate: 查询条件 |
异常类型
| 异常类型 | 说明 | HTTP状态码 |
|---|---|---|
NotFoundException |
资源未找到 | 404 |
BusinessException |
业务逻辑异常 | 400 |
ValidationException |
参数校验异常 | 422 |
UnauthorizedException |
未授权访问 | 401 |
ForbiddenException |
禁止访问 | 403 |
ConflictException |
资源冲突 | 409 |
统一响应格式
// 成功响应
{
"success": true,
"code": 200,
"message": "Success",
"data": { ... }
}
// 失败响应
{
"success": false,
"code": 404,
"message": "User not found",
"data": null
}
// 分页响应
{
"success": true,
"code": 200,
"message": "Success",
"data": {
"items": [...],
"totalCount": 100,
"pageIndex": 1,
"pageSize": 10
}
}
命名空间
using Healnet.Core.Interfaces;
using Healnet.Core.Services;
using Healnet.Core.Exceptions;
using Healnet.Core.Entities;
using Healnet.Core.Responses;
许可证
MIT License
| Product | Versions 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.
-
net10.0
- Healnet.Common (>= 1.0.7)
- Microsoft.AspNetCore.Http.Abstractions (>= 2.2.0)
- Microsoft.Extensions.Logging.Abstractions (>= 8.0.0)
NuGet packages (1)
Showing the top 1 NuGet packages that depend on Healnet.Core:
| Package | Downloads |
|---|---|
|
Healnet.Infrastructure
Healnet.Infrastructure 是 Healnet 框架的基础设施层类库,提供各种基础设施服务的封装和集成,包括 Consul 服务发现、Redis 缓存、RabbitMQ 消息队列、gRPC、Elasticsearch、Milvus 向量数据库、SQLSugar ORM、JWT 认证、YARP 反向代理、OpenTelemetry 可观测性、Serilog 日志框架、ClickHouse 列式数据库等。 |
GitHub repositories
This package is not used by any popular GitHub repositories.
| Version | Downloads | Last Updated |
|---|---|---|
| 3.0.0 | 44 | 7/16/2026 |
| 2.0.7 | 99 | 7/10/2026 |
| 2.0.5 | 99 | 7/8/2026 |
| 2.0.3 | 107 | 6/30/2026 |
| 2.0.0 | 111 | 6/29/2026 |
| 1.7.3 | 104 | 6/29/2026 |
| 1.5.0 | 132 | 6/16/2026 |
| 1.4.0 | 109 | 6/15/2026 |
| 1.2.0 | 110 | 5/29/2026 |
| 1.1.1 | 106 | 5/25/2026 |
| 1.1.0 | 113 | 5/22/2026 |
| 1.0.9 | 116 | 5/20/2026 |
| 1.0.8 | 104 | 5/20/2026 |
| 1.0.7 | 101 | 5/20/2026 |
| 1.0.6 | 134 | 5/19/2026 |
| 1.0.5 | 152 | 5/13/2026 |
| 1.0.4 | 114 | 5/13/2026 |
| 1.0.3 | 119 | 5/13/2026 |
| 1.0.2 | 110 | 5/13/2026 |
| 1.0.1 | 112 | 5/13/2026 |
Loading failed
Initial release of Healnet.Core