DcsvIo.D2.Validation.Abstractions
0.1.29
dotnet add package DcsvIo.D2.Validation.Abstractions --version 0.1.29
NuGet\Install-Package DcsvIo.D2.Validation.Abstractions -Version 0.1.29
<PackageReference Include="DcsvIo.D2.Validation.Abstractions" Version="0.1.29" />
<PackageVersion Include="DcsvIo.D2.Validation.Abstractions" Version="0.1.29" />
<PackageReference Include="DcsvIo.D2.Validation.Abstractions" />
paket add DcsvIo.D2.Validation.Abstractions --version 0.1.29
#r "nuget: DcsvIo.D2.Validation.Abstractions, 0.1.29"
#:package DcsvIo.D2.Validation.Abstractions@0.1.29
#addin nuget:?package=DcsvIo.D2.Validation.Abstractions&version=0.1.29
#tool nuget:?package=DcsvIo.D2.Validation.Abstractions&version=0.1.29
DcsvIo.D2.Validation.Abstractions
Audience: backend .NET service engineers and any consumer that depends on email, phone, or postal-code validation, the shared field-length bounds, or the name/sex taxonomy enums - without committing to a specific implementation.
Interface contracts for the D2 validator family plus the shared field-constraints
catalog (codegen-emitted field-length constants + closed-list taxonomy enums). Domain
code anywhere in the backend can reference this package without pulling in a
phone-number library, regex catalog, or DI container. This is the lowest shared
vocabulary layer, and every consumer depends on it: the validator interfaces, the
FieldConstraints bounds that limit what value-object Create(...) calls accept, and the
NamePrefix / NameSuffix / BiologicalSex taxonomy enums.
Install
dotnet add package DcsvIo.D2.Validation.Abstractions
Interfaces
| Interface | Signature | Returns |
|---|---|---|
IEmailValidator |
Validate(string? email) |
Ok with trimmed + lowercased address; ValidationFailed with per-field InputError |
IPhoneValidator |
Validate(string? phone, CountryCode? defaultRegion = null) |
Ok with E.164-normalized number; ValidationFailed with per-field InputError |
IPostalCodeValidator |
Validate(string? postalCode, CountryCode? countryCode = null) |
Ok with trimmed + uppercased code; ValidationFailed with per-field InputError |
All the interfaces share the same return contract: D2Result<string> - normalized
value on success, ValidationFailed carrying structured InputError field diagnostics
on failure.
Field-constraints catalog (codegen-emitted)
Spec-driven from contracts/validation/field-constraints.spec.json via
DcsvIo.D2.Validation.SourceGen - emitted at build time into Generated/ (committed,
linguist-generated). The same spec generates the TypeScript @dcsv-io/d2-validation-abstractions
catalog, so .NET and TypeScript cannot drift apart.
FieldConstraints (static class of public const int)
Field-length / digit-count bounds. The bounds are generous but finite: they reject garbage and never real
human data. The value objects (contacts + Location) and the frontend Zod schemas read these
to limit what Create(...) accepts.
| Constant | Value | Applies to |
|---|---|---|
FIRST_NAME_MAX / MIDDLE_NAME_MAX / LAST_NAME_MAX / PREFERRED_NAME_MAX |
255 | person name fields |
COMPANY_NAME_MAX / JOB_TITLE_MAX / DEPARTMENT_MAX |
255 | professional fields |
STREET_LINE_MAX / CITY_MAX |
255 | address fields |
COMPANY_WEBSITE_MAX |
2048 | raw company-website URL |
AFFIX_CUSTOM_MAX |
64 | custom name prefix / suffix |
POSTAL_CODE_MAX |
16 | postal / ZIP code |
EMAIL_MAX |
254 | email address |
PHONE_E164_MAX |
32 | raw phone-number string |
PHONE_MIN_DIGITS / PHONE_MAX_DIGITS |
7 / 15 | phone digit-count floor / ceiling |
Taxonomy enums (byte-backed, [JsonConverter(typeof(JsonStringEnumConverter))])
Closed-list string-wire vocabularies. The member name IS the wire form; unknown wire codes
throw JsonException at the deserialization boundary (strict policy).
| Enum | Members |
|---|---|
NamePrefix |
Mr, Ms, Miss, Mrs, Mx, Dr, Prof, Sir, Lady, Lord, RtHon, Rev, Fr, Pr, Sr, Elder, Other |
NameSuffix |
Jr, Sr, I-X (ordinals), Other |
BiologicalSex |
Male, Female, Intersex, Unspecified (absence sentinel; no Other) |
The catalog has no localized display strings (member names are adequate for display);
frontend labels use i18n TK.* keys if a picker needs them.
Consumers
- .NET services - inject via DI; implementations live in
DcsvIo.D2.Validation. - Frontend parity - the TypeScript mirror package
@dcsv-io/d2-validation-abstractionsdefines the equivalent interfaces AND the same codegen-emittedFieldConstraints+ taxonomy enums (with Zod schemas) so client-side validation stays in sync with the server.
The postal-code twin
DcsvIo.D2.Validation.Abstractions.IPostalCodeValidator (this package) is the
country-aware validator - it accepts a CountryCode and applies country-specific
format rules. A deliberately distinct twin exists at
DcsvIo.D2.Location.IPostalCodeValidator: that is the country-blind boundary
validator used by value-object construction (global-range regex only). The two share
a short name but are namespace-distinct by design. Consumers needing both may alias
one with a using directive.
Dependencies
DcsvIo.D2.Result-D2Result<string>return type for all the interfaces.DcsvIo.D2.Geo.Abstractions-CountryCodeparameter onIPhoneValidatorandIPostalCodeValidator.DcsvIo.D2.Validation.SourceGen(analyzer;ReferenceOutputAssembly="false",PrivateAssets="all") - emits theFieldConstraints+ taxonomy catalog at build time; no runtime closure impact.
Zero DI / implementation / IO dependencies.
Telemetry
No telemetry surface - this lib emits no spans or metrics. Consumers instrument the validator call sites in their own OTel setup.
Configuration
No configuration - zero-config; the contracts have no tunable behavior.
| 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)
- 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 (4)
Showing the top 4 NuGet packages that depend on DcsvIo.D2.Validation.Abstractions:
| Package | Downloads |
|---|---|
|
DcsvIo.D2.Validation
Default validators for D2 - email, phone, and postal-code validation backed by libphonenumber-csharp and a ported postcode dataset. |
|
|
DcsvIo.D2.Location
Hash-deduplicatable geographic value objects for D2 - coordinates, street and admin addresses, deterministic identity hashes, and the postal-code validator contract. |
|
|
DcsvIo.D2.Contacts
Composable, self-redacting PII value objects for D2 - immutable Create-constructed building blocks (name, demographics, professional, email, phone) that fold into host entities. |
|
|
DcsvIo.D2.Location.EntityFrameworkCore
Reusable Entity Framework Core mapping for the DcsvIo.D2.Location value objects, applied via infra IEntityTypeConfiguration. |
GitHub repositories
This package is not used by any popular GitHub repositories.