XiHan.Framework.Persistence.Abstractions 5.0.0-preview.2

Prefix Reserved
This is a prerelease version of XiHan.Framework.Persistence.Abstractions.
dotnet add package XiHan.Framework.Persistence.Abstractions --version 5.0.0-preview.2
                    
NuGet\Install-Package XiHan.Framework.Persistence.Abstractions -Version 5.0.0-preview.2
                    
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="XiHan.Framework.Persistence.Abstractions" Version="5.0.0-preview.2" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="XiHan.Framework.Persistence.Abstractions" Version="5.0.0-preview.2" />
                    
Directory.Packages.props
<PackageReference Include="XiHan.Framework.Persistence.Abstractions" />
                    
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 XiHan.Framework.Persistence.Abstractions --version 5.0.0-preview.2
                    
#r "nuget: XiHan.Framework.Persistence.Abstractions, 5.0.0-preview.2"
                    
#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 XiHan.Framework.Persistence.Abstractions@5.0.0-preview.2
                    
#: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=XiHan.Framework.Persistence.Abstractions&version=5.0.0-preview.2&prerelease
                    
Install as a Cake Addin
#tool nuget:?package=XiHan.Framework.Persistence.Abstractions&version=5.0.0-preview.2&prerelease
                    
Install as a Cake Tool

XiHan.Framework.Persistence.Abstractions

关于

XiHan.Framework.Persistence.Abstractions 定义持久化的契约:仓储 IRepository<TEntity, TKey>、查询 EntityQuery<T>、工作单元 IUnitOfWork、实体登记与标识生成。一般由 Provider 包带入,业务代码只依赖本包,换 Provider 不改代码;写自定义 Provider 时直接引用。

主要特性

  • 仓储是聚合的集合视图,可恢复的失败以 Result 返回,批量方法逐项返回结果
  • 工作单元由框架在 Transaction 阶段自动开启、提交或回滚,数据库事务延迟到第一次写入才开
  • 用 [EntityIndex] 在实体类上声明索引,各 Provider 建出同名索引
  • 标识生成:GUID v7,可选雪花 long 标识

如何使用

安装

dotnet add package XiHan.Framework.Persistence.Abstractions --prerelease

使用

先登记实体并装配一个 Provider(Standard 自带内存实现),再注入仓储读写。仓储只在调用的工作单元里工作。

builder.Services.AddRepository<Order, Guid>();
builder.AddXiHan(x => x.UseStandardProfile());

public sealed class OrderCatalog(IRepository<Order, Guid> orders)
{
    public Task<IReadOnlyList<Order>> LargestAsync(int minAmount, CancellationToken ct)
        => orders.ListAsync(
            EntityQuery.All<Order>()
                .Where(Specification.Of<Order>(o => o.Amount >= minAmount))
                .OrderBy(static o => o.Amount, descending: true)
                .Page(0, 20),
            ct);
}

需要 long 标识时显式装配雪花特性;多实例部署要给每个实例配置互不相同的 XiHan:Persistence:Snowflake:WorkerId,或装配跨进程的分布式缓存:

builder.AddXiHan(x => x.UseStandardProfile().UseFeature<SnowflakeIdFeature>());

主要类型

此库提供的主要类型:

  • IRepository<TEntity, TKey>:查找、查询、计数、新增、更新、删除及批量版本
  • EntityQuery<T>:过滤、排序、分页
  • IUnitOfWork:事务边界与当前租户
  • EntityIndexAttribute:声明索引
  • IIdGenerator<TKey>、SnowflakeIdFeature:标识生成与雪花标识

更多文档

相关包

反馈与贡献

XiHan.Framework.Persistence.Abstractions 以 MIT 许可证 开源。欢迎到 GitHub 仓库 提交问题和贡献。

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 (13)

Showing the top 5 NuGet packages that depend on XiHan.Framework.Persistence.Abstractions:

Package Downloads
XiHan.Framework.Messaging.Abstractions

曦寒框架消息抽象包

XiHan.Framework.Profiles.Standard

曦寒框架 Standard 组合包

XiHan.Framework.Persistence.Conformance

曦寒框架持久化一致性测试套件

XiHan.Framework.Persistence.InMemory

曦寒框架持久化的内存默认实现

XiHan.Framework.Workflow.InMemory

曦寒框架工作流的内存默认实现

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
5.0.0-preview.2 0 11/6/2026
5.0.0-preview.1 79 11/4/2026