RA.Utilities.Core.ValueObjects
· 4 min read
Version 10.2.0
Feature release: introduces the IBAN value object for validated, normalized International Bank Account Numbers with ISO 7064 mod-97 check digits and ASP.NET Core minimal API binding.
✨ New Features
IBANvalue object: Validates and normalizes International Bank Account Numbers (IBAN). Guarantees that any instance in your domain is canonical, structurally sound, and mathematically verified.- Automatic paper format normalization: Strips grouping characters (spaces, hyphens, backslashes, apostrophes) and converts to upper case on creation (
"gb82 west 1234-5698-7654-32"→"GB82WEST12345698765432"). - ISO 13616 structural validation: Validates the 2-letter country code, 2 check digits, and 9–30 alphanumeric BBAN (13–34 total characters), reporting
BaseErrorCode.IbanNotValid(NOT_VALID_IBAN) on structural failures. - ISO 7064 mod-97 check digit verification: Computes expected check digits and verifies them against the input, reporting
BaseErrorCode.IbanCheckDigits(IBAN_CHECK_DIGITS) on checksum mismatches. CountryCodeproperty: Exposes the 2-letter ISO 3166-1 alpha-2 country code extracted from the first two characters (e.g.GB).- Minimal API binding: Implements
IParsable<IBAN>, enabling route, query, and header binding in ASP.NET Core minimal APIs with automatic HTTP 400 responses on invalid input. - Built-in JSON converter: Preconfigured with
ValueObjectJsonConverter<IBAN>for string-based JSON serialization and deserialization.
📝 Notes
IBANvalidates the general ISO 13616 structural range (13–34 characters) and ISO 7064 mod-97 check digits. Consumers wishing to enforce country-specific lengths can checkCountryCodeand reportBaseErrorCode.IbanLength(IBAN_LENGTH).- The release is backward compatible; existing code compiles and behaves unchanged. See the Migration Guide for details.
Version 10.1.0
Feature release: adds Money.Subtract for currency-safe subtraction.
✨ New Features
Money.Subtract(other): returns a newMoneywith the difference of the two amounts. MirrorsAdd(other): throws aBadRequestExceptionwith aCurrencyMismatchvalidation error (AttemptedValue= the other currency,ExpectedValue= the instance currency) when the currencies differ.
var price = Money.PositiveMoney(19.99m, new Currency("EUR"));
var discount = Money.PositiveMoney(4.00m, new Currency("EUR"));
var net = price.Subtract(discount); // 15.99 EUR
// price.Subtract(new Money(4m, new Currency("USD"))) throws BadRequestException (CurrencyMismatch)
📝 Notes
Moneyis immutable:AddandSubtractreturn new instances and never mutate the operands.
Version 10.0.0
This is the first stable release of RA.Utilities.Core.ValueObjects, introducing strongly-typed, validated value objects for .NET with built-in System.Text.Json support, structured validation errors via BadRequestException, and minimal API binding through IParsable<T>.
✨ New Features
Email: A validated, normalized email value object. Trims and lowercases input, enforces a 254-character maximum, and exposesLocalPartandDomainproperties.Currency: A validated currency value object. Trims and uppercases input and enforces the 3-character ISO 4217 length.SSN: A validated social-security-number value object. Trims, uppercases, and enforces the 10-character^[A-Z][0-9]{8}[A-Z]$format.Money: A monetary amount pairing adecimalwith aCurrency, with aPositiveMoneyfactory and currency-safeAdd.IValueObject<TSelf>: A shared contract extendingIParsable<TSelf>with a normalizedValueproperty, making it easy to build your own validated value objects.ValueObjectJsonConverter<T>: A genericSystem.Text.Jsonconverter that serializes value objects as plain strings and validates them on deserialization, applied out of the box toEmail,Currency, andSSN.- Structured validation errors: Every validation failure throws a
BadRequestExceptioncarryingValidationErrorentries with property name, message, error code, attempted value, and expected value — ready for the RA.Utilities API error pipeline. - Minimal API binding:
Parse/TryParseimplementations enable route, query, and header binding in ASP.NET Core minimal APIs, with failed bindings producing automatic 400 responses.
📝 Notes
There are no breaking changes — 10.0.0 is the initial release. See the Getting Started guide to adopt the package.