Asgard.IDGen 3.1.9

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

Asgard.IDGen

概述

Asgard.IDGen 是一个基于雪花算法(Snowflake)实现的唯一ID生成器库。该库适用于需要生成全局唯一标识符的应用场景,特别适用于分布式系统中。

主要功能

  • 使用雪花算法生成唯一ID。
  • 支持自定义工作节点ID和数据中心ID。
  • 提供线程安全的ID生成方法。

安装

可以通过NuGet包管理器安装Asgard.IDGen:

dotnet add package Asgard.IDGen

使用示例

以下是一个简单的使用示例,展示如何初始化ID生成器并生成唯一ID:

using Asgard.IDGen;

class Program
{
    static void Main(string[] args)
    {
        // 初始化ID生成器,设置工作节点ID和数据中心ID
        SnowflakeIDGen.Init(workerID: 1, datacenter: 1);

        // 获取ID生成器实例
        var idGen = SnowflakeIDGen.Instance;

        // 生成唯一ID
        long uniqueId = idGen.NextId();

        Console.WriteLine($"Generated Unique ID: {uniqueId}");
    }
}

类说明

  • SnowflakeIDGen: 实现雪花算法的核心类,提供ID生成功能。
  • IdWorkSystem: 内部静态类,用于获取当前时间戳。
  • DisposableAction: 内部类,用于执行可释放操作。

注意事项

  • 在使用NextId方法之前,必须先调用Init方法进行初始化。
  • 工作节点ID和数据中心ID的范围分别为0到31。

贡献

欢迎贡献代码和提出改进建议。请参考贡献指南

许可证

本项目采用MIT许可证。详情请参见LICENSE文件。

Product Compatible and additional computed target framework versions.
.NET net8.0 is compatible.  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 was computed.  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.
  • net8.0

    • No dependencies.

NuGet packages (2)

Showing the top 2 NuGet packages that depend on Asgard.IDGen:

Package Downloads
Asgard.Hosts.AspNetCore

Asgard.Hosts.AspNetCore 提供基于 ASP.NET Core 的宿主层实现,负责应用启动与依赖注入引导、通用中间件与管道配置、端点路由、gRPC 与 Swagger 集成,以及与 Asgard 框架模块(日志、配置、扩展等)的托管适配。兼容 .NET 8,面向可扩展的微服务与 Web 应用托管。

Asgard.ConfigCenter

Asgard.ConfigCenter 是阿斯加德框架(Asgard Framework)中的一个模块,负责配置中心相关功能的实现与管理。

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
3.1.9 921 1/16/2026
3.1.8 909 1/15/2026
3.1.7 1,489 12/22/2025
3.1.6 1,804 12/11/2025
3.1.5 1,649 12/7/2025
3.1.4 2,102 12/2/2025
3.1.2 1,682 11/30/2025
3.1.1 1,671 11/30/2025
3.1.0 2,666 11/22/2025
3.0.2 1,774 11/17/2025
3.0.1 2,668 11/14/2025
3.0.0 1,637 11/5/2025