Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support Custom ID Generators #14

Open
adrianotr opened this issue May 17, 2024 · 0 comments
Open

Support Custom ID Generators #14

adrianotr opened this issue May 17, 2024 · 0 comments

Comments

@adrianotr
Copy link

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant