Dis.Uuid 1.1.0

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

Dis.Uuid

NuGet Downloads License

A high-performance .NET library for generating UUID version 7 (UUIDv7) identifiers with time-ordering capabilities.

๐ŸŽฏ What is UUID v7?

UUID version 7 is a time-ordered UUID variant that combines:

  • 48-bit timestamp (millisecond precision)
  • 12-bit random data for sub-millisecond ordering
  • 62-bit random data for uniqueness

This design ensures:

  • โœ… Chronological ordering - newer UUIDs are lexicographically greater
  • โœ… Database performance - excellent for primary keys and indexes
  • โœ… Global uniqueness - collision-resistant across distributed systems
  • โœ… Thread safety - safe for concurrent use

๐Ÿš€ Installation

dotnet add package Dis.Uuid

Or via Package Manager Console:

Install-Package Dis.Uuid

๐Ÿ“– Usage

using Dis.Uuid;

// Generate a new UUID v7
Guid id = UuidV7.New();
Console.WriteLine(id); // e.g., 018f-4230-1234-7000-abcdef123456

// Use in your models
public class Order
{
    public Guid Id { get; set; } = UuidV7.New();
    public DateTime CreatedAt { get; set; } = DateTime.UtcNow;
    // ... other properties
}

๐Ÿ”ง Features

  • High Performance: Uses Span<byte> and ThreadLocal<RandomNumberGenerator> for optimal performance
  • Thread Safe: Concurrent generation across multiple threads
  • Memory Efficient: Zero heap allocations during UUID generation
  • Standards Compliant: Follows RFC 4122 UUID v7 specification
  • .NET 8+ Optimized: Takes advantage of latest .NET performance improvements

๐Ÿ“Š Performance

UUID v7 generation is extremely fast and efficient:

// Benchmark example
var sw = Stopwatch.StartNew();
for (int i = 0; i < 1_000_000; i++)
{
    var uuid = UuidV7.New();
}
sw.Stop();
Console.WriteLine($"Generated 1M UUIDs in {sw.ElapsedMilliseconds}ms");

๐Ÿ”„ Time Ordering

One of the key benefits of UUID v7 is natural time ordering:

var id1 = UuidV7.New();
await Task.Delay(1); // Small delay
var id2 = UuidV7.New();

// id2 will always be lexicographically greater than id1
Assert.True(string.Compare(id1.ToString(), id2.ToString()) < 0);

๐ŸŽฏ Use Cases

Perfect for:

  • Database Primary Keys - Better performance than traditional UUIDs
  • Distributed Systems - Global uniqueness with time ordering
  • Event Sourcing - Natural chronological ordering of events
  • Logging Systems - Time-ordered log entries
  • Microservices - Consistent ID generation across services

๐Ÿ”’ Thread Safety

The library is fully thread-safe and can be used concurrently:

// Safe to use across multiple threads
var tasks = Enumerable.Range(0, 10)
    .Select(_ => Task.Run(() => 
    {
        var ids = new List<Guid>();
        for (int i = 0; i < 1000; i++)
        {
            ids.Add(UuidV7.New());
        }
        return ids;
    }));

var results = await Task.WhenAll(tasks);
// All generated UUIDs will be unique

๐Ÿงช Testing

The library includes comprehensive tests covering:

  • Uniqueness validation
  • Time ordering verification
  • Thread safety testing
  • Performance benchmarks

Run tests:

dotnet test

๐Ÿ“‹ Requirements

  • .NET 8.0 or higher
  • Compatible with all .NET 8+ workloads (Console, Web, Desktop, etc.)

๐Ÿค Contributing

Contributions are welcome! Please feel free to submit issues and pull requests.

  1. Fork the repository
  2. Create a feature branch
  3. Make your changes
  4. Add tests if needed
  5. Submit a pull request

๐Ÿ“„ License

This project is licensed under the BSD 3-Clause License - see the LICENSE.txt file for details.

๐Ÿ”— References


Made with โค๏ธ for the .NET community

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

    • No dependencies.
  • net8.0

    • No dependencies.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
1.1.0 181 8/20/2025
1.0.0 86 8/15/2025

v1.1.0: Added compatibility with .NET Standard 2.0 (supports .NET Core 2.0+, .NET Framework 4.6.1+)