-
|
Hi, what's the difference between Primitively and Vogen? Thanks. |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 1 reply
-
|
That's a great question for multiple reasons. Firstly, I had never heard of Vogen before, so thank you for bringing the project to my attention. I've not done a huge deep dive into Vogen yet, but here are my initial thoughts: - Vogen shares the same goal as Primitively, namely to provide a solution to "Primitive Obsession". Both projects were inspired by Andrew Lock's brilliant StronglyTypedId project. Vogen's source generation is invoked in the same way as Primitively by decorating a partial struct with an attribute. Vogen uses a single attribute (e.g. [ValueObject`1]), whereas Primitively has an attribute for each supported primitive type (e.g. [Guid], [Int]). Primitively's approach has the benefit of being able to contain type-specific properties such as Guid formats, and Integer min and max values. Vogen achieves a similar level of functionality by having the developer follow a convention by adding a Validate static method. I like this, but the motivation for having these properties in Primitively attributes was so that the source-generated types contain these values as referenceable constants that can be accessed programmatically, e.g. when generating Open API / Swagger types. Currently, Primitively requires a partial record struct to be invoked. Under the hood, this produces a read-only record struct. Vogen doesn't require the struct to be a record. Vogen source generates the C# equality comparers itself. Primitively relies on the Roslyn compiler to do this. In future versions, Primitively will be potentially updated to support structs that are not records. Vogen, as far as I can tell, uses C# analysers to help police and guide its usage. This is a brilliant feature. I would love to add this to Primitively as well. All Primitively source-generated types are backed by Primitively interfaces, e.g. IGuid, IInt. This has several benefits, such as extensibility and testability. Primitively source-generates a repository class containing all the Primitively types contained in any given assembly. This facilitates superfast DI container configuration because it prevents the need to use reflection to scan assemblies when an application starts up. Compared to Primitively, Vogen is much more popular and is supported by the open-source community. I like it a lot. Hope that helps! |
Beta Was this translation helpful? Give feedback.
-
|
Thanks for the really thoughtful answer! And thanks for pointing out the OG primitive obsession solution - I didn't know about it. |
Beta Was this translation helpful? Give feedback.
That's a great question for multiple reasons. Firstly, I had never heard of Vogen before, so thank you for bringing the project to my attention.
I've not done a huge deep dive into Vogen yet, but here are my initial thoughts: -
Vogen shares the same goal as Primitively, namely to provide a solution to "Primitive Obsession".
Both projects were inspired by Andrew Lock's brilliant StronglyTypedId project.
Vogen's source generation is invoked in the same way as Primitively by decorating a partial struct with an attribute. Vogen uses a single attribute (e.g. [ValueObject`1]), whereas Primitively has an attribute for each supported primitive type (e.g. [Guid], [Int]). Primitively's approach has…