Class CommandResult

Namespace
Cratis.Arc.Commands
Assembly
Cratis.Arc.Core.dll

Represents the result coming from executing a command.

public class CommandResult
Inheritance
CommandResult
Derived
Inherited Members
Extension Methods

Constructors

CommandResult()

public CommandResult()

Properties

AuthorizationFailureReason

Gets or sets the reason for authorization failure, if any.

public string AuthorizationFailureReason { get; set; }

Property Value

string

CorrelationId

Gets the CorrelationId associated with the command.

public CorrelationId CorrelationId { get; init; }

Property Value

CorrelationId

ExceptionMessages

Gets or sets any exception messages that might have occurred.

public IEnumerable<string> ExceptionMessages { get; set; }

Property Value

IEnumerable<string>

ExceptionStackTrace

Gets or sets the stack trace if there was an exception.

public string ExceptionStackTrace { get; set; }

Property Value

string

HasExceptions

Gets or sets whether or not there are any exceptions that occurred.

public bool HasExceptions { get; }

Property Value

bool

IsAuthorized

Gets whether or not the command was authorized to execute.

public bool IsAuthorized { get; set; }

Property Value

bool

IsSuccess

Gets whether or not the command executed successfully.

public bool IsSuccess { get; }

Property Value

bool

IsValid

Gets whether or not the command is valid.

public bool IsValid { get; }

Property Value

bool

OperationOutcomes

Gets immutable server-only observations of started operations, without descriptor payloads.

[JsonIgnore]
public IReadOnlyList<CommandOperationOutcome> OperationOutcomes { get; }

Property Value

IReadOnlyList<CommandOperationOutcome>

Recovery

Gets the server-only recovery summary, when operation declarations participated. This is not an HTTP contract.

[JsonIgnore]
public CommandRecoverySummary? Recovery { get; }

Property Value

CommandRecoverySummary

ResponseValue

Gets the response value carried by this result, if any, boxed as an object. This lets a caller read the response without knowing its concrete generic type.

protected virtual object? ResponseValue { get; }

Property Value

object

ValidationResults

Gets or sets any validation result.

public IEnumerable<ValidationResult> ValidationResults { get; set; }

Property Value

IEnumerable<ValidationResult>

Methods

ClearResponse()

Removes the response value carried by this result, if any. This lets a caller holding an untyped CommandResult remove the response without knowing its concrete generic type.

protected virtual void ClearResponse()

Remarks

A response is bound onto the result the moment the handler produces it - before the command's execution scopes complete, and therefore before a transaction has committed. Anything failing after that point leaves a result that is not successful yet still carries a value the caller must not act on. This is the seam that lets the pipeline take that value back. The base result carries no response, so this does nothing.

Error(CorrelationId, Exception)

Creates a new CommandResult representing an error.

public static CommandResult Error(CorrelationId correlationId, Exception exception)

Parameters

correlationId CorrelationId

The CorrelationId associated with the command.

exception Exception

The exception.

Returns

CommandResult

A CommandResult.

Error(CorrelationId, string)

Creates a new CommandResult representing an error.

public static CommandResult Error(CorrelationId correlationId, string message)

Parameters

correlationId CorrelationId

The CorrelationId associated with the command.

message string

The error message.

Returns

CommandResult

A CommandResult.

FromException(CorrelationId, Exception)

Creates a new CommandResult from an exception.

public static CommandResult FromException(CorrelationId correlationId, Exception exception)

Parameters

correlationId CorrelationId

The CorrelationId associated with the command.

exception Exception

The exception to convert.

Returns

CommandResult

A CommandResult.

Remarks

An exception implementing IValidationFailure represents invalid client input and becomes a validation failure (mapping to HTTP 400); any other exception becomes an error result (HTTP 500). This lets code running inside the pipeline reject a command as invalid without knowing how the result is serialized.

InvalidBody(CorrelationId)

Creates a new CommandResult representing a request body that could not be read or deserialized.

public static CommandResult InvalidBody(CorrelationId correlationId)

Parameters

correlationId CorrelationId

The CorrelationId associated with the command.

Returns

CommandResult

A CommandResult that is a validation failure (mapping to HTTP 400), carrying no internal detail.

Remarks

A malformed or wrong-typed request body is a client error, not a server fault. This surfaces it as a validation failure (so the endpoint returns 400) without echoing the underlying parser message.

MergeWith(params CommandResult[])

Merges the results of one or more CommandResult instances into this.

public void MergeWith(params CommandResult[] commandResults)

Parameters

commandResults CommandResult[]

Params of CommandResult to merge with.

MissingHandler(CorrelationId, Type)

Creates a new CommandResult representing a missing handler.

public static CommandResult MissingHandler(CorrelationId correlationId, Type type)

Parameters

correlationId CorrelationId

The CorrelationId associated with the command.

type Type

The type of command that is missing a handler.

Returns

CommandResult

A CommandResult.

Success(CorrelationId)

Creates a new CommandResult representing a successful command execution.

public static CommandResult Success(CorrelationId correlationId)

Parameters

correlationId CorrelationId

The CorrelationId associated with the command.

Returns

CommandResult

A CommandResult.

Unauthorized(CorrelationId, string?)

Creates a new CommandResult representing an unauthorized command execution.

public static CommandResult Unauthorized(CorrelationId correlationId, string? reason = null)

Parameters

correlationId CorrelationId

The CorrelationId associated with the command.

reason string

Optional reason for the authorization failure.

Returns

CommandResult

A CommandResult.