StrictGuid 1.0.0
dotnet add package StrictGuid --version 1.0.0
NuGet\Install-Package StrictGuid -Version 1.0.0
<PackageReference Include="StrictGuid" Version="1.0.0" />
<PackageVersion Include="StrictGuid" Version="1.0.0" />
<PackageReference Include="StrictGuid" />
paket add StrictGuid --version 1.0.0
#r "nuget: StrictGuid, 1.0.0"
#:package StrictGuid@1.0.0
#addin nuget:?package=StrictGuid&version=1.0.0
#tool nuget:?package=StrictGuid&version=1.0.0
StrictGuid (UUID v8)
StrictGuid is a high-performance .NET library for working with typed identifiers based on the RFC 9562 standard (UUID v8). It allows you to embed the entity type directly into the GUID, ensuring strict typing at the domain model level without sacrificing performance.
Key Features
- 🚀 Extreme Speed: 55x faster than standard
Guid.NewGuid()inFastmode. - 💎 Zero-Allocation: Zero heap allocations (0 bytes).
- 🛡️ Type-Safe: Binds IDs to your
enum : byte(supports up to 256 types). - 🔒 Entropy Choice:
Fast(Random),Secure(Crypto), andSequential(DB-friendly). - 📏 UUID v8 Compliance: Fully compliant with RFC 9562.
- 🛡️ Reliability: Strict protection against regular UUID v4 and "garbage" GUIDs.
Solution Structure
src/StrictGuid.Library: The core library (Extension methods, generator).tests/StrictGuid.Tests: Unit tests (xUnit).benchmarks/StrictGuid.Benchmarks: Performance tests (BenchmarkDotNet).samples/StrictGuid.Demo: Usage example.
Benchmark Results
Performance comparison on .NET 10.0.202 (Apple M1):
| Method | Mean | Ratio | Allocated |
|---|---|---|---|
| StandardNewGuid | 255.00 ns | 1.00 | - |
| StrictGuidFast | 4.65 ns | 0.02 | - |
| StrictGuidSequential | 27.81 ns | 0.11 | - |
| StrictGuidSecure | 256.86 ns | 1.01 | - |
| ExtractType | 6.73 ns | 0.03 | - |
The Sequential mode provides an excellent balance: it is 9x faster than a standard GUID and guarantees correct sorting (prevents index fragmentation) in the DB.
The Fast mode outperforms the regular GUID generator by 55 times.
Installation
You can install the package from NuGet via the .NET CLI:
dotnet add package StrictGuid
Or via the Package Manager Console in Visual Studio:
Install-Package StrictGuid
Usage
1. Defining Types
Your enums must be based on the byte type. You can define both domain entities and service types (e.g., logging, webhooks):
public enum EntityType : byte
{
// Service types
Log = 0,
WebHook = 1,
Request = 2,
// Domain entities
User = 3,
Order = 4,
Invoice = 5,
// ... supports up to 256 types
}
2. Generating IDs
using StrictGuid.Library;
// Sequential ID (UUID v7 style) — recommended for DBs
Guid orderId = EntityType.Order.NewStrictGuid(StrictGuidEntropy.Sequential);
// Ultra-fast random ID (for logs or transactions)
Guid logId = EntityType.Log.NewStrictGuid(StrictGuidEntropy.Fast);
// Cryptographically secure ID (tokens)
Guid secretId = EntityType.User.NewStrictGuid(StrictGuidEntropy.Secure);
3. Extraction and Validation
// Extracting type
EntityType type = id.GetEntityType<EntityType>();
// Fast validation (throws StrictGuidException on mismatch)
id.ValidateEntityType(EntityType.Order);
// Safe logical check
if (id.IsEntityType(EntityType.User))
{
// ...
}
Security and Entropy Choice
| Mode | Source | Order | When to use |
|---|---|---|---|
| Fast | Random.Shared |
Random | Regular IDs, high speed, logs. |
| Secure | Crypto |
Random | Secret tokens, passwords, sessions. |
| Sequential | Time + Random |
Sequential | Primary Keys (PK) in DB, sortable lists. |
Type Isolation and Protection against UUID v4
The library reliably isolates entity types. The validation or type extraction method is guaranteed to detect mismatches.
If a standard UUID v4 is passed to your system (e.g., generated by a normal Guid.NewGuid()), the library will not confuse it with an entity (even an entity with code 0, like Log).
The algorithm strictly checks the version bits (UUID v8 requires the value 0x80 in the upper bits of the 7th byte). If a v4 or garbage GUID is passed:
IsEntityTypewill safely returnfalse.GetEntityTypeorValidateEntityTypewill throw aStrictGuidException.
System Requirements
- .NET 8.0+, .NET 6.0, or .NET Standard 2.0
- Support for
System.Runtime.CompilerServices.Unsafe(included automatically in newer .NET, added as a NuGet package for .NET Standard 2.0)
Optimizations
AggressiveInlining&AggressiveOptimizationto eliminate call overhead.Unsafe.Asfor Zero-allocation type conversions.Span<byte>&stackallocfor stack-based memory operations.
| Product | Versions 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 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. |
-
net10.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.0.0 | 66 | 4/20/2026 |