![]() |
VOOZH | about |
dotnet add package Sparkdo.IdGeneration --version 1.0.3
NuGet\Install-Package Sparkdo.IdGeneration -Version 1.0.3
<PackageReference Include="Sparkdo.IdGeneration" Version="1.0.3" />
<PackageVersion Include="Sparkdo.IdGeneration" Version="1.0.3" />Directory.Packages.props
<PackageReference Include="Sparkdo.IdGeneration" />Project file
paket add Sparkdo.IdGeneration --version 1.0.3
#r "nuget: Sparkdo.IdGeneration, 1.0.3"
#:package Sparkdo.IdGeneration@1.0.3
#addin nuget:?package=Sparkdo.IdGeneration&version=1.0.3Install as a Cake Addin
#tool nuget:?package=Sparkdo.IdGeneration&version=1.0.3Install as a Cake Tool
Sparkdo 框架的 ID 生成库,提供多种 ID 生成策略。
dotnet add package Sparkdo.IdGeneration
基于 Twitter 的雪花算法实现,支持以下特性:
生成顺序 GUID,可以提高数据库索引性能:
生成基于 Base32 编码的字符串 ID:
配置文件示例:
{
"Sparkdo": {
"IdGeneration": {
"SnowflakeId": {
"WorkerId": 1,
"WorkerIdBitLength": 6,
"SeqBitLength": 6
}
}
}
}
使用 ID 生成器:
public class MyService
{
private readonly ILongIdGenerator _longIdGenerator;
private readonly IGuidGenerator _guidGenerator;
private readonly IStringIdGenerator _stringIdGenerator;
public MyService(
ILongIdGenerator longIdGenerator,
IGuidGenerator guidGenerator,
IStringIdGenerator stringIdGenerator)
{
_longIdGenerator = longIdGenerator;
_guidGenerator = guidGenerator;
_stringIdGenerator = stringIdGenerator;
}
public void GenerateIds()
{
// 生成雪花 ID
long snowflakeId = _longIdGenerator.Create();
// 生成顺序 GUID
Guid sequentialGuid = _guidGenerator.Create();
// 生成字符串 ID
string stringId = _stringIdGenerator.Create();
}
}
Method: 雪花计算方法(1-漂移算法|2-传统算法),默认1BaseTime: 基础时间,不能超过当前系统时间WorkerId: 机器码,必须由外部设定WorkerIdBitLength: 机器码位长,默认值6SeqBitLength: 序列数位长,默认值6MaxSeqNumber: 最大序列数,默认值0(表示取最大值)MinSeqNumber: 最小序列数,默认值5TopOverCostCount: 最大漂移次数,默认2000DataCenterId: 数据中心ID,默认0DataCenterIdBitLength: 数据中心ID长度,默认0TimestampType: 时间戳类型(0-毫秒,1-秒),默认0DefaultSequentialGuidType: 默认顺序 GUID 类型| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net10.0 net10.0 is compatible. net10.0-android net10.0-android was computed. net10.0-browser net10.0-browser was computed. net10.0-ios net10.0-ios was computed. net10.0-maccatalyst net10.0-maccatalyst was computed. net10.0-macos net10.0-macos was computed. net10.0-tvos net10.0-tvos was computed. net10.0-windows net10.0-windows was computed. |
Showing the top 3 NuGet packages that depend on Sparkdo.IdGeneration:
| Package | Downloads |
|---|---|
|
Sparkdo.EventBus
Sparkdo 事件总线实现库,提供本地和分布式事件发布/订阅功能 |
|
|
Sparkdo.Ddd.Domain
Sparkdo DDD 领域模型库,提供领域驱动设计的核心组件实现 |
|
|
Sparkdo.BackgroundJobs
Sparkdo 后台作业库,提供后台任务调度和执行功能实现 |
This package is not used by any popular GitHub repositories.
| Version | Downloads | Last Updated |
|---|---|---|
| 1.0.4-preview.3 | 188 | 6/8/2026 |
| 1.0.4-preview.2 | 184 | 6/7/2026 |
| 1.0.4-preview.1 | 182 | 6/7/2026 |
| 1.0.3 | 428 | 6/6/2026 |
| 1.0.3-preview.1 | 187 | 5/17/2026 |
| 1.0.2 | 357 | 4/27/2026 |
| 1.0.2-preview.5 | 108 | 4/15/2026 |
| 1.0.2-preview.4 | 108 | 2/8/2026 |
| 1.0.2-preview.3 | 111 | 2/1/2026 |
| 1.0.2-preview.2 | 128 | 1/31/2026 |
| 1.0.2-preview.1 | 204 | 12/4/2025 |
| 1.0.1 | 1,073 | 11/27/2025 |
| 1.0.0 | 1,014 | 11/25/2025 |
| 1.0.0-preview.5 | 157 | 10/24/2025 |