SequentialGuid 2.2.1

.NET Standard 2.0
There is a newer version of this package available.
See the version list below for details.
NuGet\Install-Package SequentialGuid -Version 2.2.1
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.
dotnet add package SequentialGuid --version 2.2.1
<PackageReference Include="SequentialGuid" Version="2.2.1" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add SequentialGuid --version 2.2.1
#r "nuget: SequentialGuid, 2.2.1"
#r directive can be used in F# Interactive, C# scripting and .NET Interactive. Copy this into the interactive tool or source code of the script to reference the package.
// Install SequentialGuid as a Cake Addin
#addin nuget:?package=SequentialGuid&version=2.2.1

// Install SequentialGuid as a Cake Tool
#tool nuget:?package=SequentialGuid&version=2.2.1

SequentialGuid

Will generate Sequential Guids based on MongoDB's ObjectId specification. Date & time are encoded into the value so you do not need to store them separately in your database

Define an interface to the signature you like

public interface IIdGenerator
{
    Guid NewId();
}

Define your implementing class which can be transient since the singleton is implemented by the framework

public class SequentialIdGenerator : IIdGenerator
{
    public Guid NewId() => SequentialGuidGenerator.Instance.NewGuid();
}

Wire it up to .NET Core dependency injection in the ConfigureServices method during application startup

public void ConfigureServices(IServiceCollection services)
{
    `services.AddTransient<IIdGenerator, SequentialIdGenerator>();`
}

Finally define a base entity for your application which will contain an id and a timestamp as soon as you initialize it. Note I do not advocate setting a default Id getter this way just illustrating it can be done

public abstract class BaseEntity
{
    public Guid Id { get; set; } = SequentialGuidGenerator.Instance.NewGuid();
    public DateTime? Timestamp => Id.ToDateTime();
    // If you really must have non-UTC time
    public DateTime? LocalTime => Id.ToDateTime()?.ToLocalTime();
}
Product Versions
.NET net5.0 net5.0-windows net6.0 net6.0-android net6.0-ios net6.0-maccatalyst net6.0-macos net6.0-tvos net6.0-windows
.NET Core netcoreapp2.0 netcoreapp2.1 netcoreapp2.2 netcoreapp3.0 netcoreapp3.1
.NET Standard netstandard2.0 netstandard2.1
.NET Framework net461 net462 net463 net47 net471 net472 net48
MonoAndroid monoandroid
MonoMac monomac
MonoTouch monotouch
Tizen tizen40 tizen60
Xamarin.iOS xamarinios
Xamarin.Mac xamarinmac
Xamarin.TVOS xamarintvos
Xamarin.WatchOS xamarinwatchos
Compatible target framework(s)
Additional computed target framework(s)
Learn more about Target Frameworks and .NET Standard.
  • .NETStandard 2.0

    • No dependencies.

NuGet packages (9)

Showing the top 5 NuGet packages that depend on SequentialGuid:

Package Downloads
BR.MicroServices.Utilities

Package Description

Loyo.EntityFramework

EntityFrameworkCore UnitOfWork Repositories

SequentialGuid.NodaTime

Provide extension methods to round trip between NodaTime Instant and sequential guid

Atomiv.Infrastructure.SequentialGuid

Package Description

Optivem.Atomiv.Infrastructure.SequentialGuid

Package Description

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
4.0.0 0 10/5/2022
3.0.1 30,779 2/22/2022
3.0.0 19,156 9/15/2021
2.5.0 205,102 11/18/2020
2.4.2 19,187 7/31/2020
2.4.1 12,625 7/8/2020
2.4.0 145,929 12/13/2017
2.2.1 1,144 10/17/2017
2.2.0 1,131 9/24/2017
1.0.0 3,315 2/17/2014

Moved to .netstandard2.0 so it can be used with .NET Core on Linux & OSX