API Reference IResult - ulfbou/Zentient.Results GitHub Wiki

πŸ“˜ API Reference: interface – IResult

Namespace: Zentient.Results Assembly: Zentient.Results.dll Available since: v0.1.0


πŸ“– Summary

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.


πŸ’‘ Design Philosophy / Rationale

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 – IsSuccess and IsFailure offer intuitive branching.
  • πŸ“¦ Structured error modeling – via ErrorInfo, compliant with application/problem+json.
  • πŸ”Œ Protocol-agnostic status – using IResultStatus for flexible mapping (e.g., HTTP status codes).
  • πŸ§ͺ Diagnostics support – Messages provide rich, non-semantic context for observability.
  • πŸ” Composability – designed for use with Map, Bind, Then, and other functional operations.

πŸ”– Type Signature

public interface IResult

πŸ“¦ Properties

1. IsSuccess

  • Type: bool
  • Summary: Indicates whether the operation completed successfully.
  • Behavior: Returns true if the result has no associated errors.

2. IsFailure

  • Type: bool
  • Summary: Indicates whether the operation failed.
  • Behavior: Always the logical negation of IsSuccess.

3. Errors

  • Type: IReadOnlyList<ErrorInfo>
  • Summary: A list of structured error records explaining why the operation failed.
  • Behavior: Empty when IsSuccess == true; populated otherwise.

4. Messages

  • Type: IReadOnlyList<string>
  • Summary: Optional diagnostics, debug output, or developer-facing hints.
  • Behavior: Present on both success and failure. Not intended for error logic.

5. ErrorMessage

  • Type: string?
  • Summary: A shortcut to the first error’s message, if any.
  • Behavior: null when the result is successful.

6. Status

  • Type: IResultStatus
  • Summary: Provides a semantic classification of the result (e.g., ValidationError, Unauthorized).
  • Behavior: Used for protocol translation and downstream response mapping.

πŸ§ͺ Usage Examples

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}");
}

🧭 Semantic Layers

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.

πŸ” Implementations

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.

⚠️ Remarks

  • IResult is strictly non-generic. Use IResult<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, and Then.

🧩 Integration and Interoperability

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.

πŸ“š See Also


🏷️ Tags

#API #ErrorModel #FunctionalCore #Immutable #ResultPattern #FluentAPI #StableContract #ZentientCore


Last Updated: 2025-06-21 Version: 0.4.0

⚠️ **GitHub.com Fallback** ⚠️