Skip to content

Support Custom ID Generators #14

Description

@adrianotr

Problem

Currently different types of Guid are supported, such as

  • Guid.NewGuid()
  • MassTransit.NewId
  • GuidComb

There's also this open issue to support Ulid.
At some point UUID v7 and v8 specs will likely need to be included.

Solution

I think it might be great if we could have a more relaxed approach to generating ids.

Something like this:

// Id type
[Strongly(newIdGenerator: typeof(MyCustomIdGenerator))]
public readonly partial struct SomeId;

// Id generator
public static class MyCustomIdGenerator
{
    public static Guid New() => NewId.NextSequentialGuid();
}

Th generated code can use the fully qualified name of MyCustomIdGenerator to call the static method New().

public static TYPENAME New() => new TYPENAME(MyProject.MyCustomIdGenerator.New());

This way the id can be generated in whatever way it's needed, no need to create a new Id type for each possible case.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions