Atya.Foundation.Results
1.2.0
Prefix Reserved
dotnet add package Atya.Foundation.Results --version 1.2.0
NuGet\Install-Package Atya.Foundation.Results -Version 1.2.0
<PackageReference Include="Atya.Foundation.Results" Version="1.2.0" />
<PackageVersion Include="Atya.Foundation.Results" Version="1.2.0" />
<PackageReference Include="Atya.Foundation.Results" />
paket add Atya.Foundation.Results --version 1.2.0
#r "nuget: Atya.Foundation.Results, 1.2.0"
#:package Atya.Foundation.Results@1.2.0
#addin nuget:?package=Atya.Foundation.Results&version=1.2.0
#tool nuget:?package=Atya.Foundation.Results&version=1.2.0
Atya.Foundation.Results
Result and Error primitives for expected, recoverable outcomes in Atya libraries.
Overview
Atya.Foundation.Results models expected failures as values. Use it for validation errors, not-found outcomes, conflicts, and upstream refusals where throwing exceptions would turn normal control flow into error handling.
The package is intentionally small and dependency-free: Error, ErrorKind, Result, and Result<T>.
Installation
dotnet add package Atya.Foundation.Results
Install-Package Atya.Foundation.Results
<PackageReference Include="Atya.Foundation.Results" Version="<latest-stable>" />
Quick Start
using Atya.Foundation.Results;
static Result<string> ValidateName(string? name)
{
if (string.IsNullOrWhiteSpace(name))
{
return Result.Failure<string>(
"atya.foundation.results.name-required",
"A name is required.",
ErrorKind.Validation);
}
return Result.Success(name);
}
var message = ValidateName("Atya").Match(
value => $"Hello, {value}.",
error => $"{error.Code}: {error.Message}");
The console sample compiles this same pattern: https://github.com/AtyaLibraries/Results/tree/development/samples/Results.Samples.Console
Feature Tour
Error
Error carries a stable code, a human-readable message, an ErrorKind, an optional Target, and child Details. Details is an immutable snapshot. ErrorKind includes the transient kinds Unavailable (7), Timeout (8) and TooManyRequests (9). ToString() on Result and Result<T> never throws and never prints the success value (Success or Failure(code)).
var error = new Error(
"atya.foundation.results.not-found",
"The requested item was not found.",
ErrorKind.NotFound);
Use Target for the field, property, or resource the error applies to. Use Details for structured child errors, such as one child per validation failure.
var error = new Error(
"atya.foundation.results.validation",
"Validation failed.",
target: null,
details:
[
new Error(
"atya.foundation.results.name-required",
"A name is required.",
target: "Name",
kind: ErrorKind.Validation),
],
kind: ErrorKind.Validation);
Details is never null; constructors copy the supplied child list. Error equality is structural: Code, Message, Kind, Target, and the ordered child Details all participate in equality and hash-code generation.
Result
Use Result when an operation has no success value.
Result outcome = Result.Success();
Result failed = Result.Failure("atya.foundation.results.conflict", "The item changed.", ErrorKind.Conflict);
Result<T>
Use Result<T> when an operation returns a value on success.
Result<int> parsed = Result.Success(42);
Result<string> text = parsed.Map(value => value.ToString(CultureInfo.InvariantCulture));
Match, Map, and Bind
Match converts both states to a single value. Map transforms only the success value. Bind chains another result-returning operation and propagates failures.
Result<int> loaded = Result.Success(42);
Result<string> formatted = loaded
.Bind(value => value > 0
? Result.Success(value.ToString(CultureInfo.InvariantCulture))
: Result.Failure<string>("atya.foundation.results.invalid", "Value must be positive.", ErrorKind.Validation));
Error Codes
Error codes should be stable, lowercase, and owned by the package or application concept that emits them. Atya packages use the shape atya.{area}.{name}.{error}.
This package documents these sample codes in tests and samples:
| Code | Meaning |
|---|---|
atya.foundation.results.name-required |
Sample validation failure. |
atya.foundation.results.failure |
Generic test failure. |
Consumers should define their own domain-specific codes rather than reusing sample codes.
Dependencies
This package has no runtime dependencies.
Compatibility
Targets net10.0.
Links
| 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
- No dependencies.
NuGet packages (6)
Showing the top 5 NuGet packages that depend on Atya.Foundation.Results:
| Package | Downloads |
|---|---|
|
Atya.Errors.ProblemDetails
Problem Details helpers for ASP.NET Core Atya services. |
|
|
Atya.Errors.Validation
Validation primitives and error helpers for Atya error handling packages. |
|
|
Atya.Application.Mediator
Source-generated, reflection-free mediator contracts and dispatch for .NET applications. |
|
|
Atya.Http.Client
Typed HttpClient helpers that return Atya Result values, map RFC 9457 problem responses, and propagate correlation. |
|
|
Atya.Data.Pagination
ORM-agnostic paging primitives and paged result shapes for .NET services. |
GitHub repositories
This package is not used by any popular GitHub repositories.