A .NET source generator and analyzer that creates validated value objects from primitives to combat primitive obsession.
Vogen is a .NET source generator and analyzer that automatically creates validated value objects from primitive types. It solves the problem of primitive obsession by wrapping types like `int` or `string` in domain-specific wrappers (e.g., `CustomerId`, `AccountBalance`) that enforce validation rules at compile time.
.NET developers building domain-driven applications who need to enforce business rules and type safety beyond what primitives offer, especially those concerned with code correctness and maintainability.
Developers choose Vogen because it provides compile-time safety against invalid data, eliminates boilerplate code for value objects, and maintains performance nearly identical to using primitives directly, all while integrating seamlessly with popular .NET libraries.
A semi-opinionated library which is a source generator and a code analyser. It Source generates Value Objects
Open-Awesome is built by the community, for the community. Submit a project, suggest an awesome list, or help improve the catalog on GitHub.
Introduces new C# compilation errors to block unsafe patterns like 'new' or 'default', preventing invalid objects from entering your domain at build time.
Benchmarks show minimal speed and memory impact compared to using primitives directly, with struct-based value objects matching native int performance.
Includes ready-to-use converters for popular libraries like System.Text.Json, Newtonsoft.Json, Dapper, and EFCore, reducing integration boilerplate.
Allows defining validation via a static Validate method that returns a Validation result, throwing configurable exceptions on failure for domain-specific rules.
Some integrations, like EFCore, require explicit converter registration in OnModelCreating, adding complexity and potential for misconfiguration.
Prohibits user-defined constructors and enforces a factory pattern, which can be restrictive for teams accustomed to more flexible object creation.
Relies on .NET source generators, which may not work seamlessly in all build environments, especially older .NET Framework projects requiring specific LangVersion settings.
Focuses on wrapping single primitive types; creating value objects for composite data requires additional manual effort or workarounds.