Trellis.Core
3.0.0-alpha.304
dotnet add package Trellis.Core --version 3.0.0-alpha.304
NuGet\Install-Package Trellis.Core -Version 3.0.0-alpha.304
<PackageReference Include="Trellis.Core" Version="3.0.0-alpha.304" />
<PackageVersion Include="Trellis.Core" Version="3.0.0-alpha.304" />
<PackageReference Include="Trellis.Core" />
paket add Trellis.Core --version 3.0.0-alpha.304
#r "nuget: Trellis.Core, 3.0.0-alpha.304"
#:package Trellis.Core@3.0.0-alpha.304
#addin nuget:?package=Trellis.Core&version=3.0.0-alpha.304&prerelease
#tool nuget:?package=Trellis.Core&version=3.0.0-alpha.304&prerelease
Trellis.Core
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, andEnsure. - Model optional data with
Maybe<T>instead ofnull. - Return typed errors that map cleanly to APIs, logs, and tests.
- Use
AsTask()/AsValueTask()to return synchronousResultchains 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 returnedMicrosoft.AspNetCore.Http.IResultwrites the body itself; the struct never reaches STJ. - Non-HTTP — unwrap with
Match/TryGetValuebefore serialization. - Genuinely need raw JSON (logging, IPC) — register a converter (or a
JsonConverterFactory) inJsonSerializerOptions.Converters; option-registered converters take precedence over the type's[JsonConverter]attribute. The override must match the declared static type:JsonConverter<Result<T>>covers onlyResult<T>-declared values;IResult<T>-declared values needJsonConverter<IResult<T>>;IResult-declared values needJsonConverter<IResult>. Use aJsonConverterFactoryto cover multiple shapes at once.
Documentation
Part of Trellis
This package is part of the Trellis framework.
| 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
- OpenTelemetry.Api (>= 1.15.3)
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 |