SequentialGuid 2.2.1

There is a newer version of this package available.
See the version list below for details.
Install-Package SequentialGuid -Version 2.2.1
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
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
#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
The NuGet Team does not provide support for this client. Please contact its maintainers for support.

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();
}
  • .NETStandard 2.0

    • No dependencies.

NuGet packages (8)

Showing the top 5 NuGet packages that depend on SequentialGuid:

Package Downloads
BR.MicroServices.Utilities

Package Description

Loyo.EntityFramework

EntityFrameworkCore UnitOfWork Repositories

Optivem.Atomiv.Infrastructure.SequentialGuid

Package Description

Atomiv.Infrastructure.SequentialGuid

Package Description

Celia.io.Core.MicroServices.Utilities

A part of my Celia.io.Core platform. A project for some utilized functions what I cannot find in https://github.com/dotnetcore/Util right now.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
3.0.0 2,211 9/15/2021
2.5.0 23,782 11/18/2020
2.4.2 17,780 7/31/2020
2.4.1 7,921 7/8/2020
2.4.0 121,502 12/13/2017
2.2.1 985 10/17/2017
2.2.0 975 9/24/2017
1.0.0 3,048 2/17/2014

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