Guides & Recipes — DomainPrimitives
Recipe 1: Bridging TryCreate to EricksonLopez.Result
Section titled “Recipe 1: Bridging TryCreate to EricksonLopez.Result”Because DomainPrimitives does not take a compile-time dependency on EricksonLopez.Result, bridge TryCreate cleanly at your domain boundary:
using EricksonLopez.DomainPrimitives;using EricksonLopez.Result;
namespace Example.DomainPrimitives;
[Email]public readonly partial record struct CustomerEmail;
public static class EmailResultAdapter{ public static Result<CustomerEmail> ParseEmail(string raw) => CustomerEmail.TryCreate(raw, out var email, out var err) ? Result.Success(email) : Result.Failure<CustomerEmail>(Error.Validation( err.Code ?? "Email.Invalid", err.Message ?? "Invalid email address."));}Use generated Match / Switch methods (v2.0.0+) for exhaustive compile-time handling, or PrimitiveBuilder<TPrimitive, TValue> (EricksonLopez.DomainPrimitives.Advanced) for multi-step construction.
Recipe 3: Testing with DomainPrimitiveFakeFactory
Section titled “Recipe 3: Testing with DomainPrimitiveFakeFactory”EricksonLopez.DomainPrimitives.Testing ships DomainPrimitiveFakeFactory (Strings, Numerics, Identifiers, Dates, Shortcuts), DomainPrimitiveScenarios, DomainPrimitiveTestBuilder, and DomainPrimitiveVerifyExtensions.