Pattern for UUID v7 with Guid-wrapping Value Objects (+ feature suggestion) #912
KaineVarley
started this conversation in
Ideas
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Hi Steve,
First off - great library! We're migrating ~15 hand-rolled record value objects to Vogen in a .NET 10 / EF Core 10 project and it's a huge improvement.
We hit an interesting situation with
Customizations.AddFactoryMethodForGuidsthat I wanted to share in case others encounter it, plus a potential enhancement idea.The situation
Our project uses UUID v7 (
Guid.CreateVersion7()) for all identifier generation - it gives us time-ordered, index-friendly GUIDs in our Azure SQL database. This was a deliberate migration fromGuid.NewGuid()(UUID v4).The
AddFactoryMethodForGuidscustomisation generatesFromNewGuid()which (as far as we can tell from the generated code) callsGuid.NewGuid()internally - producing UUID v4. Enabling it in our project would silently regress our UUID v7 migration.Our pattern
We chose not to enable
AddFactoryMethodForGuidsand instead added a custom static factory method to each Guid-wrapping VO:This works well because:
From(), so all validation is preservedOrderId.New()which is clean and intention-revealingFeature suggestion
Would it be worth adding a
Customizations.AddFactoryMethodForVersion7Guidsoption that generatesFromNewGuid()usingGuid.CreateVersion7()instead ofGuid.NewGuid()?Since
Guid.CreateVersion7()is available from .NET 9+, this could be conditionally generated based on target framework. UUID v7 adoption is growing rapidly for database primary keys, so this might help a lot of users.Alternatively, a more flexible approach could be a
Customizations.AddFactoryMethodForGuidsthat accepts a configuration for whichGuidcreation method to use.Either way, the manual
New()pattern above works fine - just thought it might be useful to others!Thanks for Vogen - it's a genuinely excellent library.
All reactions