-
Notifications
You must be signed in to change notification settings - Fork 21
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
Create a static wrapper type (or value object) similar to Guid for strong typing #37
Comments
This can already be done in userland by declaring your own custom types, or better yet, using things like Vogen (which is a great library). [ValueObject<int>]
public readonly partial struct SqidsId; // you could also add methods like `Validate`, static factories, etc. Could you elaborate on what need you specifically have and how it's not already doable by defining your own types? |
I am familiar with Vogen and was originally trying to use that, but that would require a whole lot of additional code to handle model binding, json conversion and other stuff since your primitive will be an integer, while publicly facing (and in ToString) it should be displayed as string. |
I have to ask again: "How is this not already doable by defining your own types"? |
Yes of course I can implement it myself, but that is with anything, I could write my own implementation of sqid, I could write my own implementation of value objects etc, the ability for me being able to do it myself isn't the point. I think this feature would improve the developer experience because they don't have to do it themselves. Besides strongly typed is something that should be strived for anyway, it makes it easier to recognise if a property is just a string or if its supposed to represent a sqid. |
I think it's a good point. For example, a library that's a bit similar: https://github.com/Cysharp/Ulid |
It would be great if this implementation could be wrapped in a static class similar to Guid so strong typing is allowed inside the domain.
The text was updated successfully, but these errors were encountered: