Sparkdo.Uow 1.0.1

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

Sparkdo.Uow

Sparkdo 工作单元实现库,提供完整的工作单元模式实现。

功能特性

  • 完整的工作单元模式实现
  • 事务管理支持
  • 数据库 API 管理
  • 事件发布机制
  • 与 Sparkdo 框架无缝集成
  • 支持嵌套工作单元
  • 支持工作单元保留和恢复

安装

<PackageReference Include="Sparkdo.Uow" Version="x.x.x" />

核心组件

UnitOfWork

工作单元核心实现,提供工作单元模式的基本功能:

  • Id: 工作单元唯一标识符
  • Options: 配置选项
  • Outer: 外层工作单元引用
  • SaveChangesAsync(): 保存更改
  • CompleteAsync(): 完成工作单元(提交事务)
  • RollbackAsync(): 回滚工作单元
  • Reserve(): 保留工作单元
  • 事件:Failed(失败事件)、Disposed(释放事件)

DefaultUnitOfWorkManager

默认工作单元管理器实现,用于创建和管理工作单元:

  • Current: 获取当前工作单元
  • BeginAsync(): 开始新的工作单元
  • ReserveAsync(): 保留工作单元
  • BeginReserved(): 开始已保留的工作单元
  • TryBeginReserved(): 尝试开始已保留的工作单元

UnitOfWorkOptions

工作单元配置选项实现:

  • IsTransactional: 是否启用事务
  • IsolationLevel: 事务隔离级别
  • Timeout: 超时时间(毫秒)

扩展类

  • UnitOfWorkExtensions: 工作单元扩展方法
  • UnitOfWorkManagerExtensions: 工作单元管理器扩展方法
  • UnitOfWorkHelper: 工作单元助手类

拦截器

  • UnitOfWorkInterceptor: 工作单元拦截器,用于自动管理工作单元
  • UnitOfWorkInterceptorConfigure: 工作单元拦截器配置

模块配置

  • SparkdoUnitOfWorkModule: 工作单元模块配置

使用示例

基本用法

public class MyService
{
    private readonly IUnitOfWorkManager _unitOfWorkManager;

    public MyService(IUnitOfWorkManager unitOfWorkManager)
    {
        _unitOfWorkManager = unitOfWorkManager;
    }

    [UnitOfWork]
    public async Task DoWorkAsync()
    {
        // 在事务中执行操作
        // 工作单元会自动提交或回滚
    }

    public async Task DoWorkManuallyAsync()
    {
        using var uow = await _unitOfWorkManager.BeginAsync(true);
        try
        {
            // 执行操作
            await uow.CompleteAsync();
        }
        catch
        {
            await uow.RollbackAsync();
            throw;
        }
    }
}

配置选项

// 在 Startup.cs 或 Program.cs 中配置
services.Configure<SparkdoUnitOfWorkDefaultOptions>(options =>
{
    options.TransactionBehavior = UnitOfWorkTransactionBehavior.Enabled;
    options.IsolationLevel = IsolationLevel.ReadCommitted;
    options.Timeout = 30000; // 30秒
});

扩展性

该库提供了完整的工作单元实现,可以通过以下方式扩展:

  1. 实现自定义的 IDatabaseApiITransactionApi 来提供数据库和事务操作
  2. 实现自定义的 IUnitOfWorkEventPublisher 来处理工作单元事件发布
  3. 通过自定义特性或拦截器来增强工作单元功能

代码结构说明

本项目包含以下主要组件:

核心实现

  • UnitOfWork: 工作单元核心实现
  • DefaultUnitOfWorkManager: 默认工作单元管理器实现
  • UnitOfWorkOptions: 工作单元配置选项实现
  • SparkdoUnitOfWorkDefaultOptions: 工作单元默认配置选项

扩展类

  • UnitOfWorkExtensions: 工作单元扩展方法
  • UnitOfWorkManagerExtensions: 工作单元管理器扩展方法
  • UnitOfWorkHelper: 工作单元助手类

拦截器

  • UnitOfWorkInterceptor: 工作单元拦截器
  • UnitOfWorkInterceptorConfigure: 工作单元拦截器配置

辅助类

  • ChildUnitOfWork: 子工作单元实现
  • AmbientUnitOfWork: 环境工作单元实现
  • EventOrderGenerator: 事件顺序生成器
  • AlwaysDisableTransactionsUnitOfWorkManager: 总是禁用事务的工作单元管理器

模块配置

  • SparkdoUnitOfWorkModule: 工作单元模块配置

所有公共接口和类都添加了详细的 XML 文档注释,便于开发者理解和使用。

Product Compatible and additional computed target framework versions.
.NET net5.0 was computed.  net5.0-windows was computed.  net6.0 was computed.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 was computed.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 was computed.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed.  net9.0 was computed.  net9.0-android was computed.  net9.0-browser was computed.  net9.0-ios was computed.  net9.0-maccatalyst was computed.  net9.0-macos was computed.  net9.0-tvos was computed.  net9.0-windows was computed.  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. 
.NET Core netcoreapp2.0 was computed.  netcoreapp2.1 was computed.  netcoreapp2.2 was computed.  netcoreapp3.0 was computed.  netcoreapp3.1 was computed. 
.NET Standard netstandard2.0 is compatible.  netstandard2.1 was computed. 
.NET Framework net461 was computed.  net462 was computed.  net463 was computed.  net47 was computed.  net471 was computed.  net472 was computed.  net48 was computed.  net481 was computed. 
MonoAndroid monoandroid was computed. 
MonoMac monomac was computed. 
MonoTouch monotouch was computed. 
Tizen tizen40 was computed.  tizen60 was computed. 
Xamarin.iOS xamarinios was computed. 
Xamarin.Mac xamarinmac was computed. 
Xamarin.TVOS xamarintvos was computed. 
Xamarin.WatchOS xamarinwatchos was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages (2)

Showing the top 2 NuGet packages that depend on Sparkdo.Uow:

Package Downloads
Sparkdo.Data

Sparkdo 数据库连接管理库,提供数据库连接字符串解析、数据过滤等功能

Sparkdo.AspNetCore

Sparkdo ASP.NET Core 集成库,提供与 ASP.NET Core 框架深度集成的功能实现

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
1.0.2-preview.4 123 2/8/2026
1.0.2-preview.3 131 2/1/2026
1.0.2-preview.2 155 1/31/2026
1.0.2-preview.1 207 12/4/2025
1.0.1 1,942 11/27/2025
1.0.0 1,957 11/25/2025
1.0.0-preview.5 134 10/24/2025