API Reference Result - ulfbou/Zentient.Results GitHub Wiki
Namespace:
Zentient.ResultsAssembly:Zentient.Results.dllAvailable since:v0.1.0
Represents the standard non-generic implementation of IResult, encapsulating success/failure state, structured errors, diagnostic messages, and a semantic status code for operations that do not return a value.
Resultprovides a reliable, fluent foundation for command-style or void-returning operations in a consistent, exception-free manner.
The Result class follows a functional, declarative, and transport-agnostic model, ideal for outcome-based programming. It encourages the propagation of structured failures over exceptions and facilitates clear control flow.
- ๐ Binary Outcome Semantics โ Clear success/failure via
IsSuccess,IsFailure. - ๐งฑ Structured Error Modeling โ Integrates
ErrorInfofor semantic error representation. - ๐ซ Void-Compatible โ Designed for operations where no return value is needed.
- โ๏ธ Composable & Adapter-Ready โ Works well in CQRS, middleware, and HTTP/gRPC layers.
- ๐ Trace-Aware โ Supports diagnostic messages for enhanced observability and auditing.
public sealed class Result : IResult-
Signature:
public Result(IReadOnlyList<ErrorInfo> errors, IResultStatus status, IReadOnlyList<string> messages) -
Summary: Initializes a fully-defined result instance with explicit outcome metadata.
-
Parameters:
-
errors(IReadOnlyList<ErrorInfo>): List of structured errors (empty for success). -
status(IResultStatus): Semantic result status. -
messages(IReadOnlyList<string>): Diagnostic messages (optional).
-
-
Remarks: Use static factory methods for clearer semantics and intent.
-
Signature:
public static Result Success() - Summary: Returns a success result with no errors.
-
Return Value:
Result: An instance withIsSuccess == true, no errors, andResultStatus.Success.
var result = Result.Success();-
Signature:
public static Result Failure(IEnumerable<ErrorInfo> errors, IResultStatus status) -
Summary: Creates a failed result with errors and a failure status.
-
Parameters:
-
errors(IEnumerable<ErrorInfo>): One or more structured errors. -
status(IResultStatus): Semantic status.
-
-
Return Value:
Result: A failed result instance.
-
Signature:
public static Result FromException(Exception exception) -
Summary: Converts an unhandled exception into a failed result.
-
Parameters:
-
exception(Exception): The thrown exception.
-
-
Return Value:
Result: A failed result with anErrorInfoderived from the exception.
-
Type:
IReadOnlyList<ErrorInfo> - Summary: Structured list of errors.
- Behavior: Empty on success. Each error carries rich metadata.
-
Type:
IReadOnlyList<string> - Summary: Diagnostic or audit messages associated with the operation.
- Behavior: Optional, always present (can be empty).
-
Type:
IResultStatus - Summary: Protocol-agnostic status (e.g., validation error, unauthorized).
- Behavior: Used for mapping to HTTP/gRPC/etc.
-
Type:
bool - Summary: Indicates whether the operation succeeded.
-
Behavior:
trueifErrorsis empty.
-
Type:
bool - Summary: Indicates whether the operation failed.
-
Behavior:
trueifErrors.Count > 0.
-
Type:
string? - Summary: Shortcut to the first error's message.
-
Behavior:
nullif the result is successful.
public IResult SaveUser(User user)
{
if (!user.IsValid())
{
return Result.Failure(new[] {
ErrorInfo.Create("InvalidUser", "User failed validation.")
}, ResultStatus.FailedValidation);
}
userRepository.Save(user);
return Result.Success();
}var result = SaveUser(user);
if (result.IsFailure)
{
logger.LogError(result.ErrorMessage);
}- Designed for operations where no return value is expected (
voidsemantics). - Should be composed with extension methods such as
Bind,Then, andMatch. - Implements
IResultand guarantees immutability, serialization compatibility, and structured behavior.
| Component / Layer | Role |
|---|---|
| CQRS Command Handlers | Common return type for CommandResult-style operations |
| HTTP Adapters | Converts into ProblemDetails via Zentient.Endpoints.Http |
| gRPC | Translated to status metadata using GrpcResultAdapter
|
| Telemetry/Tracing | Supports diagnostics via Messages and Zentient.Telemetry hooks |
| Validation | Composed with rule engine outputs via ErrorInfo.Create(...)
|
IResultErrorInfoResult<T>ResultTransformationExtensions- Error Architecture
#API #VoidResult #ErrorHandling #Immutability #ZentientCore #StructuredErrors
Last Updated: 2025-06-21 Version: 0.4.0