Sparkdo.IdGeneration 2.0.0-preview.2

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

Sparkdo.IdGeneration

Sparkdo.IdGeneration 提供 Sparkdo V 的默认 Id 生成运行时:UUID v7、ULID 字符串和 Snowflake long

本包通过 package manifest 声明默认服务、Options 和 lifecycle,不提供 AddSparkdoIdGeneration() 手工启用入口,也不包含 IdGeneration bootstrap contribution。

默认实现

服务 默认实现 行为
IGuidGenerator / IIdGenerator<Guid> Version7GuidGenerator 调用 Guid.CreateVersion7()
IStringIdGenerator / IIdGenerator<string> UlidStringIdGenerator 生成 26 位 Crockford Base32 ULID。
ILongIdGenerator / IIdGenerator<long> SnowflakeLongIdGenerator 共享 singleton SnowflakeIdState
IIdGeneratorProvider DefaultIdGeneratorProvider 提供默认、内置名称和 keyed 扩展解析。

内置名称固定为 guidulidsnowflake。默认注册使用 TryAdd,应用预注册的服务优先。

Snowflake 生命周期

Snowflake 使用 41-bit timestamp + 10-bit worker id + 12-bit sequence。应用 startup lifecycle 会先通过 IDistributedLock 获取并续租 worker id;只有 startup 成功后才能调用 ILongIdGenerator.Create()

以下状态均 fail closed:

  • startup 尚未获取 lease;
  • worker lease 已丢失;
  • 物理时钟发生回拨;
  • timestamp 超出 41-bit 范围。

同步生成路径不会等待异步锁,也不会在 lease 丢失后自动重连。

配置

SnowflakeIdGeneratorOptions 提供 EpochWorkerLeaseDurationWorkerRenewalInterval。默认 epoch 为 2025-01-01T00:00:00Z,lease duration 为 30 秒,renewal interval 为 10 秒。renewal interval 必须严格短于 lease duration。

应用负责提供符合部署范围的 IDistributedLock。同进程多 Host、跨进程或跨机器生成 Snowflake Id 时,必须使用共享的真实分布式锁 provider。

完整使用说明、边界和验证命令见仓库中的 src/id-generation/README.md

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

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

Package Downloads
Sparkdo.Ddd.Domain

Sparkdo DDD 领域模型库,提供领域驱动设计的核心组件实现

Sparkdo.BackgroundJobs

Sparkdo 后台作业库,提供后台任务调度和执行功能实现

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
2.0.0-preview.2 25 7/20/2026
2.0.0-preview.1 33 7/18/2026
1.0.4-preview.3 200 6/8/2026
1.0.4-preview.2 199 6/7/2026
1.0.4-preview.1 198 6/7/2026
1.0.3 443 6/6/2026
1.0.3-preview.1 200 5/17/2026
1.0.2 366 4/27/2026
1.0.2-preview.5 119 4/15/2026
1.0.2-preview.4 116 2/8/2026
1.0.2-preview.3 118 2/1/2026
1.0.2-preview.2 135 1/31/2026
1.0.2-preview.1 209 12/4/2025
1.0.1 1,079 11/27/2025
1.0.0 1,022 11/25/2025
1.0.0-preview.5 165 10/24/2025