Installing Vogen
dotnet add package Vogen --version 4.0.14
NuGet\Install-Package Vogen -Version 4.0.14
When added to your project, the source generator generates the wrappers for your primitives and the code analyzer will let you know if you try to create invalid Value Objects.
Vogen consists of two dlls:
Vogen.dll
- this is the source generator and analyzers and is not needed at runtimeVogen.SharedTypes.dll
- this contains the types that are referenced at runtime, e.g.ValueObjectValidationException
andValueObjectOrError
which is used by theTryFrom
method.
Unlike using some other source generators, specifying PrivateAssets="all" ExcludeAssets="runtime"
with Vogen will cause exceptions at runtime because of missing types.
Vogen.SharedTypes.dll
is about 18KB, so will add little to your application's size. It is referenced on its own. Here is a snippet from a deps.json
file with it specified: