CommandValidator

fun interface CommandValidator

Functional interface for validating command payloads before execution.

Commands implementing this interface can perform custom validation logic on their payload data. Validation ensures that commands contain valid, consistent data before being processed by aggregates, preventing invalid state changes and improving system reliability.

The validation is typically executed early in the command processing pipeline, allowing for fast failure of invalid commands.

See also

me.ahoo.wow.command.CommandValidationException

thrown when validation fails

me.ahoo.wow.command.DefaultCommandGateway

for where validation is typically invoked

Example usage:

data class CreateUserCommand(
val email: String,
val password: String
) : CommandValidator {

override fun validate() {
require(email.isNotBlank()) { "Email cannot be blank" }
require(password.length >= 8) { "Password must be at least 8 characters" }
require(email.contains("@")) { "Email must be valid format" }
}
}

Throws

me.ahoo.wow.command.CommandValidationException

when validation rules are violated

for invalid input parameters

for invalid object state

Functions

Link copied to clipboard
abstract fun validate()

Validates the command payload for correctness and consistency.