DcsvIo.D2.Contacts
0.1.29
dotnet add package DcsvIo.D2.Contacts --version 0.1.29
NuGet\Install-Package DcsvIo.D2.Contacts -Version 0.1.29
<PackageReference Include="DcsvIo.D2.Contacts" Version="0.1.29" />
<PackageVersion Include="DcsvIo.D2.Contacts" Version="0.1.29" />
<PackageReference Include="DcsvIo.D2.Contacts" />
paket add DcsvIo.D2.Contacts --version 0.1.29
#r "nuget: DcsvIo.D2.Contacts, 0.1.29"
#:package DcsvIo.D2.Contacts@0.1.29
#addin nuget:?package=DcsvIo.D2.Contacts&version=0.1.29
#tool nuget:?package=DcsvIo.D2.Contacts&version=0.1.29
DcsvIo.D2.Contacts
Audience: Backend .NET service engineers attaching contact details (names, demographics, professional info, email, phone) to their own domain entities.
Composable, self-redacting PII value objects for handlers and service code. The package contains these immutable
sealed recordtypes:Personal,NameAffixes,Demographics,Professional,EmailAddress,PhoneNumber. Each is constructed through aCreate(...)smart constructor that returnsD2Result<T>. A host embeds the value objects in its own entities; the reusable Entity Framework Core mapping is in the separate packageDcsvIo.D2.Contacts.EntityFrameworkCore.
Install
dotnet add package DcsvIo.D2.Contacts
Purpose
Each value object runs a structural check (the "floor") at the start of its Create(...) factory: length caps from
the shared FieldConstraints catalog plus shape and coherence rules. It then constructs the record. EmailAddress
and PhoneNumber also accept an optional validator that the caller passes in (IEmailValidator / IPhoneValidator).
When a validator is supplied, it is the only authority, and the factory passes on its normalized output and failure
messages unchanged. When it is omitted, the structural floor applies. Every failure carries a TK.* translation key,
never a bare string.
Pure-domain layer policy: the package depends only on DcsvIo.D2.Result (D2Result factories),
DcsvIo.D2.Validation.Abstractions (the FieldConstraints caps, the NamePrefix / NameSuffix / BiologicalSex
taxonomy enums, and the validator contracts), DcsvIo.D2.Utilities (boundary helpers + the [RedactData] attribute +
the hash canonicalizer), and DcsvIo.D2.Geo.Abstractions (the CountryCode forwarded to the phone validator). It has
no infrastructure dependencies, no Entity Framework dependency and no observability surface.
Public API surface
The records live in DcsvIo.D2.Contacts.ValueObjects; each record has its own file.
ValueObjects/Personal.cs- requiredFirstNameplus optionalMiddleName,LastName,PreferredName, each cleaned and length-capped. Has a stable correlationHashId("v1." + SHA-256 hex) derived from the first / middle / last names - the preferred name is excluded so a display-name change leaves the identity digest stable. Case-, diacritic-, and whitespace-equivalent inputs hash identically.Personal.Create(firstName, middleName?, lastName?, preferredName?)→D2Result<Personal>.
ValueObjects/NameAffixes.cs- optional honorificPrefix(NamePrefix?) +Suffix(NameSuffix?) drawn from closed taxonomies, each with anOthervalue that takes a custom free-text value. A custom value is required when (and only when) its enum isOther. The all-null record is rejected.NameAffixes.Create(prefix?, prefixCustom?, suffix?, suffixCustom?)→D2Result<NameAffixes>.
ValueObjects/Demographics.cs- optionalDateOfBirth(NodaTime.LocalDate?, not in the future, not more than 150 years in the past) +BiologicalSex(BiologicalSex?). The all-null record is rejected. The date-of-birth bounds resolve "today" from an injectableDcsvIo.D2.Time.IClock(defaults toSystemClock), viaclock.GetCurrentInstant().InUtc().Date, so boundary behavior is deterministic under test.Demographics.Create(dateOfBirth?, biologicalSex?, clock?)→D2Result<Demographics>.
ValueObjects/Professional.cs- requiredCompanyNameplus optionalJobTitle,Department, andCompanyWebsite. The website is accepted as raw text and stored as an absolutehttp/httpsUri?(raw input length-capped before parsing).Professional.Create(companyName, jobTitle?, department?, companyWebsite?)→D2Result<Professional>.
ValueObjects/EmailAddress.cs- thin wrapper over a normalizedValue. Floor mode trims / collapses / lowercases / shape-checks and enforces the address-length cap; validator mode returns the injectedIEmailValidatorresult.EmailAddress.Create(value, validator?)→D2Result<EmailAddress>.
ValueObjects/PhoneNumber.cs- thin wrapper over a normalizedValue. Floor mode strips non-digits, enforces the 7-15 digit envelope and the raw-length cap, and stores a digit string; validator mode forwards the optionalCountryCode regionto the injectedIPhoneValidatorand returns its (typically E.164) result. The region is ignored in floor mode.PhoneNumber.Create(value, validator?, region?)→D2Result<PhoneNumber>.
Floor vs. validator seam
EmailAddress and PhoneNumber model a floor / validator split:
- Floor (no validator) - a structural check reusing the shared
TryParseEmail()/TryParsePhoneNumber()boundary helpers. Structural-invalid failures return the commonTK.Common.Validation.EMAIL_INVALID/PHONE_INVALIDkeys; the contacts-specific length ceilings addTK.Contacts.Validation.EMAIL_TOO_LONG/PHONE_TOO_LONGin addition. - Validator (injected) - when a caller passes an
IEmailValidator/IPhoneValidator, that validator is the sole authority. Its normalized output is trusted without a second length check (double-bounding could falsely reject a legitimately longer normalized form), and its failure result - messages, input errors, and all metadata - is propagated verbatim viaD2Result<T>.BubbleFail.
Security / PII
The value objects self-redact: PII properties carry [RedactData(Reason = RedactReason.PersonalInformation)] and are masked automatically by the Serilog destructuring policy.
| Value object | Redacted (masked in logs) | Visible (left unredacted) |
|---|---|---|
Personal |
FirstName, MiddleName, LastName, PreferredName |
HashId (one-way SHA-256 digest, correlation-safe) |
NameAffixes |
PrefixCustom, SuffixCustom (free text) |
Prefix, Suffix (closed-list enums, coarse) |
Demographics |
DateOfBirth, BiologicalSex (special-category) |
- |
Professional |
CompanyName, JobTitle, Department |
CompanyWebsite (public URL, not identifying) |
EmailAddress |
Value |
- |
PhoneNumber |
Value |
- |
Personal.HashId is a one-way SHA-256 digest of the normalized name fields - opaque, non-reversible, and safe to
correlate in logs and traces without leaking the underlying names.
Telemetry
N/A - this package contains only value objects and has no telemetry surface. Handlers that use them provide any telemetry.
Configuration / Options
N/A - no env vars, no appsettings, no Options record. The length caps come from the shared FieldConstraints catalog;
the smart-validator seam is a per-call argument.
Usage examples
using DcsvIo.D2.Contacts.ValueObjects;
using DcsvIo.D2.Geo.Abstractions;
using DcsvIo.D2.Validation.Abstractions;
// 1. Personal - required first name; carries a correlation HashId.
var personalResult = Personal.Create("John", middleName: "Quincy", lastName: "Adams");
if (!personalResult.Success)
return personalResult.AsFailure<MyAggregate>(); // propagate ValidationFailed
// 2. EmailAddress - floor mode (structural validation only).
var emailResult = EmailAddress.Create(" John.Adams@Example.com ");
// emailResult.Data.Value == "john.adams@example.com"
// 3. PhoneNumber - validator mode (smart validator is the authority).
var phoneResult = PhoneNumber.Create(
"212 555 1234",
validator: _phoneValidator, // injected IPhoneValidator
region: CountryCode.US); // forwarded to the validator only
Important / usage notes
The value objects are immutable. Composition into a host entity and the reusable EF Core per-value-object mapping
helpers (complex-type and value-converter wiring, max-length application, anonymization defaults) are in the separate
package DcsvIo.D2.Contacts.EntityFrameworkCore; this core library has no Entity Framework dependency and no
migrations.
Personal.HashId is a content digest, so a change to the normalization algorithm would change the digest for inputs
that previously hashed identically, with no error. The PersonalTests suite checks determinism, case / diacritic /
whitespace collapse, and the preferred-name-excluded invariant.
References
DcsvIo.D2.Validation.Abstractions- theFieldConstraintscaps, the taxonomy enums, and theIEmailValidator/IPhoneValidatorcontracts this lib consumes.DcsvIo.D2.Utilities- the boundary helpers (CleanStr,Falsey,Truthy,ToNullIfEmpty),NormalizeForHash, and theTryParseEmail/TryParsePhoneNumberfloor helpers.
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | 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. |
-
net10.0
- DcsvIo.D2.Geo.Abstractions (= 0.1.29)
- DcsvIo.D2.Result (= 0.5.8)
- DcsvIo.D2.Time (= 0.2.11)
- DcsvIo.D2.Utilities (= 0.3.10)
- DcsvIo.D2.Validation.Abstractions (= 0.1.29)
- JetBrains.Annotations (>= 2025.2.4)
- Microsoft.Extensions.DependencyInjection.Abstractions (>= 10.0.7)
- Microsoft.Extensions.Logging.Abstractions (>= 10.0.7)
- Microsoft.Extensions.Options (>= 10.0.7)
- Microsoft.IdentityModel.Tokens (>= 8.18.0)
- NodaTime (>= 3.2.2)
NuGet packages (1)
Showing the top 1 NuGet packages that depend on DcsvIo.D2.Contacts:
| Package | Downloads |
|---|---|
|
DcsvIo.D2.Contacts.EntityFrameworkCore
Reusable Entity Framework Core mapping for the DcsvIo.D2.Contacts value objects, applied via infra IEntityTypeConfiguration. |
GitHub repositories
This package is not used by any popular GitHub repositories.