onClose

Register a callback to be invoked when this definition is closed/released. Used within withOptions { } block.

Useful for cleanup operations like closing connections, releasing resources, etc.

Parameters

onClose

Callback function that receives the instance being closed

Example:

single { DatabaseConnection() } withOptions {
onClose { connection ->
connection.close()
}
}