API Reference IResult - ulfbou/Zentient.Results GitHub Wiki
Namespace:
Zentient.ResultsAssembly:Zentient.Results.dllAvailable since:v0.1.0
Represents the contract for a non-generic operation result, expressing whether an operation succeeded or failed, along with structured error information, semantic status, and diagnostic messages.
This interface serves as the cornerstone of result-driven workflows in the Zentient Framework, enabling clean, consistent, and composable error-aware programming.
IResult is designed to provide a standardized, immutable, protocol-agnostic representation of the outcome of an operation without carrying a return value. It enables fluent error propagation, compositional logic, and seamless adaptation to various transport protocols (e.g., HTTP, gRPC).
Key goals and principles:
- β
Binary outcome clarity β
IsSuccessandIsFailureoffer intuitive branching. - π¦ Structured error modeling β via
ErrorInfo, compliant withapplication/problem+json. - π Protocol-agnostic status β using
IResultStatusfor flexible mapping (e.g., HTTP status codes). - π§ͺ Diagnostics support β
Messagesprovide rich, non-semantic context for observability. - π Composability β designed for use with
Map,Bind,Then, and other functional operations.
public interface IResult-
Type:
bool - Summary: Indicates whether the operation completed successfully.
-
Behavior: Returns
trueif the result has no associated errors.
-
Type:
bool - Summary: Indicates whether the operation failed.
-
Behavior: Always the logical negation of
IsSuccess.
-
Type:
IReadOnlyList<ErrorInfo> - Summary: A list of structured error records explaining why the operation failed.
-
Behavior: Empty when
IsSuccess == true; populated otherwise.
-
Type:
IReadOnlyList<string> - Summary: Optional diagnostics, debug output, or developer-facing hints.
- Behavior: Present on both success and failure. Not intended for error logic.
-
Type:
string? - Summary: A shortcut to the first errorβs message, if any.
-
Behavior:
nullwhen the result is successful.
-
Type:
IResultStatus -
Summary: Provides a semantic classification of the result (e.g.,
ValidationError,Unauthorized). - Behavior: Used for protocol translation and downstream response mapping.
IResult result = authService.Login(user, password);
if (result.IsSuccess)
{
Console.WriteLine("Login successful.");
}
else
{
Console.WriteLine($"Login failed: {result.ErrorMessage}");
foreach (var error in result.Errors)
Console.WriteLine($" - {error.Code}: {error.Message}");
}| Layer | Member(s) | Purpose |
|---|---|---|
| Binary Outcome |
IsSuccess, IsFailure
|
High-level branching decision. |
| Structured Error |
Errors, ErrorMessage
|
Granular failure diagnostics and categorization. |
| Semantic Status | Status |
Protocol-agnostic outcome mapping (e.g., HTTP 400, gRPC code 3). |
| Observability | Messages |
Logging, audit trails, trace data; not part of error classification. |
| Type | Description |
|---|---|
Result |
Default implementation for non-generic result handling. |
Result<T> |
Generic variant with value support. |
HttpResult |
Transport-aware HTTP implementation using ProblemDetails. |
GrpcResult |
gRPC-adapted result with trailer/metadata support. |
-
IResultis strictly non-generic. UseIResult<T>for return-value scenarios. - Error information is always represented by
ErrorInfo, never plain strings or exceptions. - Results should be treated as immutable after creation.
- Recommended usage includes composition through functional extensions like
Map,Bind, andThen.
| Layer | Integration |
|---|---|
| Error Modeling | Backed by ErrorInfo
|
| Adapters | Mapped via HttpResultAdapter, GrpcResultAdapter, or MessagingAdapter. |
| CQRS Pipelines | Used as the core return type in handler contracts. |
| Observability | Enriched via Zentient.Telemetry.ITelemetryEnricher. |
IResult<T>ErrorInfoIResultStatusResult- Error Modeling Principles
#API #ErrorModel #FunctionalCore #Immutable #ResultPattern #FluentAPI #StableContract #ZentientCore
Last Updated: 2025-06-21 Version: 0.4.0