SequentialGuid 2.2.1

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.  Supports standard Guids as well as SQL Server guids.

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.

SequentialGuid

Will generate Sequential Guids based on MongoDB's ObjectId specification. Date &amp; 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();
}

SequentialGuid

Will generate Sequential Guids based on MongoDB's ObjectId specification. Date &amp; 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();
}

Release Notes

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

  • .NETStandard 2.0

    • No dependencies.

This package is not used by any popular GitHub repositories.

Version History

Version Downloads Last updated
2.4.0 29,282 12/13/2017
2.2.1 476 10/17/2017
2.2.0 446 9/24/2017
1.0.0 1,007 2/17/2014