Trellis.Core 3.0.0-alpha.304

This is a prerelease version of Trellis.Core.
dotnet add package Trellis.Core --version 3.0.0-alpha.304
                    
NuGet\Install-Package Trellis.Core -Version 3.0.0-alpha.304
                    
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="Trellis.Core" Version="3.0.0-alpha.304" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Trellis.Core" Version="3.0.0-alpha.304" />
                    
Directory.Packages.props
<PackageReference Include="Trellis.Core" />
                    
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 Trellis.Core --version 3.0.0-alpha.304
                    
#r "nuget: Trellis.Core, 3.0.0-alpha.304"
                    
#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 Trellis.Core@3.0.0-alpha.304
                    
#: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=Trellis.Core&version=3.0.0-alpha.304&prerelease
                    
Install as a Cake Addin
#tool nuget:?package=Trellis.Core&version=3.0.0-alpha.304&prerelease
                    
Install as a Cake Tool

Trellis.Core

NuGet Package

Railway-oriented error handling for .NET with Result<T>, Maybe<T>, and typed errors.

Installation

dotnet add package Trellis.Core

Quick Example

using Trellis;

Result<string> email = Result.Ok("ada@example.com")
    .Ensure(value => value.Contains('@'),
        Error.InvalidInput.ForField("email", "validation.error", "Email is invalid."))
    .Map(value => value.Trim().ToLowerInvariant());

Key Features

  • Compose success and failure paths with Bind, Map, Tap, and Ensure.
  • Model optional data with Maybe<T> instead of null.
  • Return typed errors that map cleanly to APIs, logs, and tests.
  • Use AsTask() / AsValueTask() to return synchronous Result chains from async-shaped APIs.
  • Build resource-aware HTTP errors tersely with ResourceRef.For<TResource>(id).
  • Define custom Required*<TSelf> value objects with source-generated parsing, JSON conversion, and tracing support.

Result<T> is not directly JSON-serializable

Result<T> carries a default [JsonConverter] that throws NotSupportedException on direct JsonSerializer.Serialize / Deserialize. Returning a raw Result<T> from a controller would otherwise silently produce {"IsSuccess": true, "Value": ..., "Error": null} with no HTTP status-code mapping for Error.* cases (an Error.NotFound would render as 200 OK instead of 404). The throw fires at the first request with an actionable message. Fix paths:

  • HTTP — call .ToHttpResponse() (Trellis.Asp). The returned Microsoft.AspNetCore.Http.IResult writes the body itself; the struct never reaches STJ.
  • Non-HTTP — unwrap with Match / TryGetValue before serialization.
  • Genuinely need raw JSON (logging, IPC) — register a converter (or a JsonConverterFactory) in JsonSerializerOptions.Converters; option-registered converters take precedence over the type's [JsonConverter] attribute. The override must match the declared static type: JsonConverter<Result<T>> covers only Result<T>-declared values; IResult<T>-declared values need JsonConverter<IResult<T>>; IResult-declared values need JsonConverter<IResult>. Use a JsonConverterFactory to cover multiple shapes at once.

Documentation

Part of Trellis

This package is part of the Trellis framework.

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

NuGet packages (10)

Showing the top 5 NuGet packages that depend on Trellis.Core:

Package Downloads
Trellis.Asp

ASP.NET Core integration for Trellis. Result-to-HTTP response mapping, scalar value validation, JSON converters (with bundled AOT source generator), and ASP.NET actor providers (Claims, Entra, Development) for Trellis.Authorization.

Trellis.Primitives

Infrastructure and ready-to-use implementations for primitive value objects in Domain-Driven Design. Includes base classes (RequiredString, RequiredGuid) with source generation, plus EmailAddress with RFC 5322 validation. Eliminates primitive obsession with strongly-typed domain primitives.

Trellis.Testing

FluentAssertions extensions and test doubles for Trellis - assert Result, Maybe, and Error types with readable fluent syntax

Trellis.Authorization

Lightweight authorization primitives for Trellis. Provides Actor, IActorProvider, IAuthorize, IAuthorizeResource of TResource, IResourceLoader, and ResourceLoaderById types that integrate with the Trellis Result type system. No dependency on any mediator or web framework.

Trellis.Mediator

Result-aware pipeline behaviors for martinothamar/Mediator. Provides validation, authorization, logging, tracing, and exception handling behaviors that understand Trellis Result types and short-circuit correctly.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
3.0.0-alpha.304 114 5/29/2026