TypeId Feature Discussion #615
drusellers
started this conversation in
Ideas
Replies: 1 comment 1 reply
-
Thanks for the link to that article, it's an interesting read. I certainly think this would be useful in Vogen. I initially thought Vogen would just be useful in the domain layer, but it's also very popular in the infrastructure layer for things like IDs. The So, we'd want something like this, but trimmed down (controlled : [ValueObject<string>]
public partial struct CustomerId
{
private static Validation Validate(string input) =>
input.StartsWith("cus_") ? Validation.Ok : Validation.Invalid("Customer IDs start with cus_");
public static CustomerId NewUnique() => From($"cus_{Guid.NewGuid()}");
} ... or using TypeId... [ValueObject<TypeIdDecoded>]
public partial struct CustomerId
{
private static Validation Validate(TypeIdDecoded input) =>
input.Type.StartsWith("cus") ? Validation.Ok : Validation.Invalid("Customer IDs start with cus_");
public static CustomerId NewUnique() => From(TypeId.New("cus"));
} Assuming this solution was adequate, we might still have issues with serialization. I'll continue to think about this and find an elegant solution. |
Beta Was this translation helpful? Give feedback.
1 reply
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
I was reading Designing APIs for humans: Object IDs looking at TypeId and wondered if there was any appetite for this library to add a concept like this.
Specifically this idea of the
type_
prefix to whatever the underlying type is.I've really been enjoying using the idea of
CustomerId
overGuid
in my code base, and the idea of going back to even something as nice asTypeId
feels like a step backwards from Vogen.So before I go down a path of either writing it myself, or looking at extending vogen I thought I would just ask and see what y'all thought first.
Cheers.
Beta Was this translation helpful? Give feedback.
All reactions