JorgeCostaMacia.ValueObject 6.0.4

Prefix Reserved
dotnet add package JorgeCostaMacia.ValueObject --version 6.0.4
                    
NuGet\Install-Package JorgeCostaMacia.ValueObject -Version 6.0.4
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="JorgeCostaMacia.ValueObject" Version="6.0.4" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="JorgeCostaMacia.ValueObject" Version="6.0.4" />
                    
Directory.Packages.props
<PackageReference Include="JorgeCostaMacia.ValueObject" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add JorgeCostaMacia.ValueObject --version 6.0.4
                    
#r "nuget: JorgeCostaMacia.ValueObject, 6.0.4"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package JorgeCostaMacia.ValueObject@6.0.4
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=JorgeCostaMacia.ValueObject&version=6.0.4
                    
Install as a Cake Addin
#tool nuget:?package=JorgeCostaMacia.ValueObject&version=6.0.4
                    
Install as a Cake Tool

JorgeCostaMacia.ValueObject

Immutable, type-safe value objects — primitives (int, long, float, double, decimal, bool, byte, string, Guid, DateTime, UTC DateTime), semantic strings (email, URL, IP, JSON), numeric/date ranges, and paging/ordering — each with the three-verb creation surface (constructor hydrates, From(...) converts unvalidated, Create(...) fabricates validated) and value equality. Every type ships a FluentValidation validator and a typed validation exception.

NuGet Downloads Build License


Install

dotnet add package JorgeCostaMacia.ValueObject

Usage

using JorgeCostaMacia.ValueObject.Domain;

EmailValueObject email = EmailValueObject.Create("user@host.com");   // validated: nothing invalid escapes Create
EmailValueObject draft = EmailValueObject.From("  user@host.com ");  // normalized but UNVALIDATED (composites' path)
string raw = email.Value;                                            // access the underlying value explicitly
string same = email;                                                 // or implicitly (VO -> primitive operator)

UuidValueObject id = UuidValueObject.Create(Guid.NewGuid());
DateTimeUtcValueObject when = DateTimeUtcValueObject.Create(DateTime.UtcNow);   // tags Utc kind; convert wall-clock at the call site

The three-verb creation surface

Each value object exposes exactly three ways in, on its natural primitive (convert other types at the call site):

  • new X(value) — hydrates raw, no normalization, no validation. Reserved for infrastructure (ORMs, deserializers — the EF converters use it).
  • X.From(value) — converts: normalizes and materializes, unvalidated. Composites build their parts through it so the whole object validates in one pass.
  • X.Create(value) — fabricates validated: runs the type's validator and throws its typed …ValidationException (with the complete failure list) on violation.

Each type's validator also assembles itself: EmailValueObjectValidator.Create() chains the Create() of the validators it composes — or take the constructor and inject the composition via DI:

EmailValueObjectValidator.Create().ValidateAndThrow(email);   // throws EmailValueObjectValidationException on failure

Deriving your own value object

Derive from the matching base and keep the type inside the contract — a public hydration constructor plus your own From and Create (the inherited ones return the base type, so re-declare them with new static returning yours), each on the natural primitive:

public sealed record ClientName : StringValueObject
{
    public ClientName(string value) : base(value) { }                       // hydration ctor

    public new static ClientName From(string value) => new(Convert(value)); // Convert is the base's protected cleanser

    public new static ClientName Create(string value)
    {
        ClientName vo = From(value);
        ClientNameValidator.Create().ValidateAndThrow(vo);                  // your FluentValidation validator
        return vo;
    }
}

This surface is required, not optional: the ecosystem depends on it — the EF converters rehydrate through the constructor, deserializers too — so every value object here carries it and a contract test keeps it that way.

Register the validators

services.AddValueObjectContext();   // registers every IValidator<…> for the value objects

Requirements

One of the following SDKs: .NET 8 / 9 / 10 (.NET 10 recommended).

Depends on JorgeCostaMacia.Exception and FluentValidation.

About

JorgeCostaMacia.ValueObject is part of shared-net — a set of foundational, self-contained .NET packages, each scoped to a single concern and reusable across your bounded contexts.

Author: Jorge Costa Maciá

Product 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. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages (1)

Showing the top 1 NuGet packages that depend on JorgeCostaMacia.ValueObject:

Package Downloads
JorgeCostaMacia.ValueObject.EfConverter

Native EF Core value converters for JorgeCostaMacia.ValueObject value objects — one converter per value-object family (value object <-> underlying value) plus a convention to auto-apply them. Provider-agnostic (works with Npgsql, SQL Server, SQLite, ...).

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
6.0.4 72 7/22/2026
6.0.3 63 7/22/2026
6.0.2 123 7/19/2026
6.0.1 116 7/15/2026
6.0.0 118 7/13/2026
5.0.0 119 7/12/2026
4.3.0 109 7/12/2026
4.2.0 114 7/11/2026
4.1.0 114 7/10/2026
4.0.0 121 7/9/2026
3.0.1 119 7/8/2026
2.0.8 101 7/1/2026
2.0.7 99 6/30/2026
2.0.6 118 6/30/2026
2.0.5 107 6/30/2026
2.0.4 119 6/30/2026
1.0.0 115 6/29/2026