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
CorrelationId
Gets the CorrelationId associated with the command.
public CorrelationId CorrelationId { get; init; }
Property Value
ExceptionMessages
Gets or sets any exception messages that might have occurred.
public IEnumerable<string> ExceptionMessages { get; set; }
Property Value
ExceptionStackTrace
Gets or sets the stack trace if there was an exception.
public string ExceptionStackTrace { get; set; }
Property Value
HasExceptions
Gets or sets whether or not there are any exceptions that occurred.
public bool HasExceptions { get; }
Property Value
IsAuthorized
Gets whether or not the command was authorized to execute.
public bool IsAuthorized { get; set; }
Property Value
IsSuccess
Gets whether or not the command executed successfully.
public bool IsSuccess { get; }
Property Value
IsValid
Gets whether or not the command is valid.
public bool IsValid { get; }
Property Value
OperationOutcomes
Gets immutable server-only observations of started operations, without descriptor payloads.
[JsonIgnore]
public IReadOnlyList<CommandOperationOutcome> OperationOutcomes { get; }
Property Value
Recovery
Gets the server-only recovery summary, when operation declarations participated. This is not an HTTP contract.
[JsonIgnore]
public CommandRecoverySummary? Recovery { get; }
Property Value
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
ValidationResults
Gets or sets any validation result.
public IEnumerable<ValidationResult> ValidationResults { get; set; }
Property Value
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
correlationIdCorrelationIdThe CorrelationId associated with the command.
exceptionExceptionThe exception.
Returns
Error(CorrelationId, string)
Creates a new CommandResult representing an error.
public static CommandResult Error(CorrelationId correlationId, string message)
Parameters
correlationIdCorrelationIdThe CorrelationId associated with the command.
messagestringThe error message.
Returns
FromException(CorrelationId, Exception)
Creates a new CommandResult from an exception.
public static CommandResult FromException(CorrelationId correlationId, Exception exception)
Parameters
correlationIdCorrelationIdThe CorrelationId associated with the command.
exceptionExceptionThe exception to convert.
Returns
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
correlationIdCorrelationIdThe 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
commandResultsCommandResult[]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
correlationIdCorrelationIdThe CorrelationId associated with the command.
typeTypeThe type of command that is missing a handler.
Returns
Success(CorrelationId)
Creates a new CommandResult representing a successful command execution.
public static CommandResult Success(CorrelationId correlationId)
Parameters
correlationIdCorrelationIdThe CorrelationId associated with the command.
Returns
Unauthorized(CorrelationId, string?)
Creates a new CommandResult representing an unauthorized command execution.
public static CommandResult Unauthorized(CorrelationId correlationId, string? reason = null)
Parameters
correlationIdCorrelationIdThe CorrelationId associated with the command.
reasonstringOptional reason for the authorization failure.