ImanSoftware.GuidGenerator 1.0.0

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

ImanSoftware.GuidGenerator

Version: 1.0.0 | Last Updated: August 2026

A flexible and testable GUID generation library for .NET with support for both Sequential and Random GUIDs.

ImanSoftware.GuidGenerator abstracts GUID generation behind a simple interface, allowing applications to use database-friendly sequential GUIDs or traditional random GUIDs through dependency injection.


Installation

Install the package using the .NET CLI:

dotnet add package ImanSoftware.GuidGenerator

Why GuidGenerator?

Calling Guid.NewGuid() directly tightly couples your code to a specific implementation and always produces random GUIDs.

In many database systems, sequential GUIDs significantly reduce index fragmentation and improve insert performance.

Instead of:

var id = Guid.NewGuid();

Use:

var id = _guidGenerator.NewGuid();

This approach improves testability while allowing the GUID generation strategy to be configured in one place.

Benefits include:

  • Better database performance with sequential GUIDs
  • Dependency Injection friendly
  • Easy unit testing
  • Configurable generation strategy
  • Lightweight and dependency-free

Features

  • IGuidGenerator abstraction
  • ✅ Sequential GUID generator
  • ✅ Random GUID generator
  • ✅ Configurable implementation
  • ✅ Dependency Injection support
  • ✅ Mock-friendly design
  • ✅ Database-optimized sequential GUIDs
  • ✅ Zero configuration

IGuidGenerator

The core abstraction exposes a single method for generating GUIDs.

public interface IGuidGenerator
{
    Guid NewGuid();
}

SequentialGuidGenerator

Generates sequential GUIDs optimized for database indexes.

Benefits include:

  • Reduced index fragmentation
  • Faster inserts
  • Better clustered index performance
  • Suitable for SQL Server and similar databases

Example:

Guid id = _guidGenerator.NewGuid();

RandomGuidGenerator

Generates standard random GUIDs equivalent to Guid.NewGuid().

Suitable for:

  • Distributed systems
  • Public identifiers
  • General-purpose applications

Dependency Injection

By default, the package registers the sequential implementation.

services.AddGuidGenerator();

This registers:

SequentialGuidGenerator

To use random GUIDs instead:

services.AddGuidGenerator(GuidGeneratorImplementationType.Random);

Example

using ImanSoftware.GuidGenerator;

public class ProductService
{
    private readonly IGuidGenerator _guidGenerator;

    public ProductService(IGuidGenerator guidGenerator)
    {
        _guidGenerator = guidGenerator;
    }

    public void CreateProduct()
    {
        var id = _guidGenerator.NewGuid();

        // Business logic...
    }
}

Unit Testing

Because GUID generation is abstracted behind an interface, it can easily be mocked.

var mock = new Mock<IGuidGenerator>();

mock.Setup(x => x.NewGuid())
    .Returns(Guid.Parse("11111111-1111-1111-1111-111111111111"));

This makes tests deterministic and repeatable.


Design Goals

  • High performance
  • Database-friendly
  • Dependency Injection compatible
  • Lightweight
  • Easy to configure
  • Mock-friendly
  • Framework independent
  • Clean Architecture compatible
  • Minimal API

Requirements

  • .NET Standard 2.0+
  • .NET 6+
  • .NET 7+
  • .NET 8+
  • .NET 9+
  • .NET 10.0+

Author

Iman Estiri

📧 contact.imanestiri@gmail.com

📧 dev.imanestiri@gmail.com

GitHub:

https://github.com/ImanEstiri


License

This project is licensed under the MIT License.

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

Showing the top 1 NuGet packages that depend on ImanSoftware.GuidGenerator:

Package Downloads
ImanSoftware.Framework

Umbrella package that bundles all ImanSoftware modules for a unified development experience.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
1.0.0 157 8/3/2026