Purview.ValueObjects
1.0.1
dotnet add package Purview.ValueObjects --version 1.0.1
NuGet\Install-Package Purview.ValueObjects -Version 1.0.1
<PackageReference Include="Purview.ValueObjects" Version="1.0.1" />
<PackageVersion Include="Purview.ValueObjects" Version="1.0.1" />
<PackageReference Include="Purview.ValueObjects" />
paket add Purview.ValueObjects --version 1.0.1
#r "nuget: Purview.ValueObjects, 1.0.1"
#:package Purview.ValueObjects@1.0.1
#addin nuget:?package=Purview.ValueObjects&version=1.0.1
#tool nuget:?package=Purview.ValueObjects&version=1.0.1
Purview.ValueObjects
Source-generated scalar and complex value objects for .NET.
Adds F#-style single-case types to C#. Mark a partial struct or class with [Scalar] or [ValueObject] and the
source generator produces Create/Hydrate factories, normalization (OnNormalize), validation (OnValidate),
Empty instances, equality, comparison, implicit conversions, and JSON converters.
- DTOs – strong types with serialization/deserialization and business rules.
- Entity Framework – reference
Microsoft.EntityFrameworkCoreand the generator emits mapping members (value converters, comparers, complex-type mapping) plus aConfigureValueObjectsextension for automatic mapping. Queries use the value object type directly. - Domain models – the F#-style single-case union pattern in C#.
Quick start
[Scalar]
public readonly partial record struct EmailAddress
{
public string Value { get; }
static partial void OnNormalize(ref string value) => value = value?.Trim().ToLowerInvariant()!;
static partial void OnValidate(string value)
{
if (string.IsNullOrWhiteSpace(value))
throw new ArgumentException("Email is required.", nameof(value));
}
}
var email = EmailAddress.Create("Demo@Example.com");
// email.Value == "demo@example.com"
The manual [Scalar] form above declares the underlying property. The automatic [Scalar<T>] /
[Scalar(typeof(T))] forms have the generator declare it, and [Scalar<string>(Nullable = true)]
expresses a nullable reference scalar.
JSON serialization
Scalar value objects serialize as their underlying value. Register the converter factory on your
JsonSerializerOptions:
var options = new JsonSerializerOptions();
options.Converters.Add(new ScalarJsonConverterFactory());
Use the same options for Entity Framework JSON columns:
modelBuilder
.Entity<Customer>()
.Property(c => c.Email)
.HasColumnType("jsonb");
Entity Framework Core
When your project references Microsoft.EntityFrameworkCore, the generator emits an EF nested class per value
object (a ValueConverter/ValueComparer) and an assembly-level ConfigureValueObjects extension that maps
them automatically:
protected override void OnModelCreating(ModelBuilder modelBuilder)
{
modelBuilder.ConfigureValueObjects(); // generated into your project
}
Scalar value objects convert to their underlying primitive column; complex value objects map as EF Core complex
types (EF Core 8+) by default or JSON columns via [ValueObject(EFMapping = EntityFrameworkMapping.Json)]. Queries compare
the value object type directly — no .Value required — or the raw underlying value (c.Email == "...",
m.Id == guid). See docs/Entity-Framework.md for the full guide.
Validation with ZodSharp
Validate value objects with Purview.ZodSharp, a C# port of Zod:
- Generator-integrated – a
[Scalar]/[ValueObject]type that is also[ZodSchema]has its generatedCreatewired to the ZodSharp-generated schema (CreatethrowsZodExceptionon invalid input).ZodSchemaMode.InsteadOfHooksopts out of theOnValidatehook; implement the generatedOnZodValidate(RefineCtx<T>)hook to add Zod-compatible refinements. - Generated validators – annotate a type with
[ZodSchema]+ DataAnnotations to get a zero-allocation{Type}Schemavalidator. - Custom rules on scalars – Purview.ZodSharp ships a validation attribute for every built-in rule (for
example
[NonSentinel(Message = "…")]), and a custom[ZodRule]-mapped attribute validates the scalar as a unit and owns the reportedCode/Origin. A rule written for the underlying value is adapted automatically via the generator-emittedScalarRuleAdapter. - Schema-first – build a schema for the underlying value (
Z.String().Email(),Z.Number(),Z.Enum<>()) and construct the value object through its strictCreatefactory.
See docs/ZodSharp-Validation.md for the full guide, and the src/src/ZodSharpSample /
src/src/ZodSharp.AspNetCoreSample projects for runnable examples.
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net8.0 is compatible. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. net9.0 is compatible. net9.0-android was computed. net9.0-browser was computed. net9.0-ios was computed. net9.0-maccatalyst was computed. net9.0-macos was computed. net9.0-tvos was computed. net9.0-windows was computed. net10.0 is compatible. net10.0-android was computed. net10.0-browser was computed. net10.0-ios was computed. net10.0-maccatalyst was computed. net10.0-macos was computed. net10.0-tvos was computed. net10.0-windows was computed. net11.0 is compatible. |
-
net10.0
- No dependencies.
-
net11.0
- No dependencies.
-
net8.0
- No dependencies.
-
net9.0
- No dependencies.
NuGet packages (15)
Showing the top 5 NuGet packages that depend on Purview.ValueObjects:
| Package | Downloads |
|---|---|
|
Purview.EventSourcing
Core abstractions, aggregate types, facades, transactions, and dependency injection extensions for building event-sourced .NET applications. |
|
|
Purview.EventSourcing.SqlServer
Azure SQL and SQL Server event stream storage provider for Purview EventSourcing. |
|
|
Purview.EventSourcing.MongoDB
MongoDB event stream and snapshot storage provider for Purview EventSourcing. |
|
|
Purview.EventSourcing.AzureStorage
Azure Table Storage and Blob Storage event store provider for Purview EventSourcing, including snapshot and large-payload support. |
|
|
Purview.EventSourcing.CosmosDb
Azure Cosmos DB queryable snapshot storage provider for Purview EventSourcing. |
GitHub repositories
This package is not used by any popular GitHub repositories.
| Version | Downloads | Last Updated |
|---|---|---|
| 1.0.1 | 69 | 10/8/2026 |
| 1.0.0 | 97 | 10/7/2026 |
| 1.0.0-prerelease.11 | 69 | 9/30/2026 |
| 1.0.0-prerelease.10 | 68 | 9/29/2026 |
| 1.0.0-prerelease.9 | 144 | 9/28/2026 |
| 1.0.0-prerelease.8 | 66 | 9/28/2026 |
| 1.0.0-prerelease.7 | 77 | 9/27/2026 |
| 1.0.0-prerelease.6 | 158 | 9/25/2026 |
| 1.0.0-prerelease.5 | 143 | 9/24/2026 |
| 1.0.0-prerelease.4 | 73 | 9/20/2026 |
| 1.0.0-prerelease.3 | 81 | 9/20/2026 |
| 1.0.0-prerelease.2 | 158 | 9/18/2026 |
| 1.0.0-prerelease.1 | 76 | 9/18/2026 |