Class: Sequent::Core::CommandService

Inherits:
Object
  • Object
show all
Defined in:
lib/sequent/core/command_service.rb

Overview

Single point in the application where subclasses of Sequent::Core::BaseCommand are executed. This will initiate the entire flow of:

  • Validate command

  • Call correct Sequent::Core::BaseCommandHandler

  • CommandHandler decides which Sequent::Core::AggregateRoot (s) to call

  • Events are stored in the Sequent::Core::EventStore

  • Unit of Work is cleared

Instance Method Summary collapse

Instance Method Details

#execute_commands(*commands) ⇒ Object

Executes the given commands in a single transactional block as implemented by the transaction_provider

For each command:

  • All filters are executed. Any exception raised will rollback the transaction and propagate up

  • If the command is valid all command_handlers that handles_message? is invoked

  • The repository commits the command and all uncommitted_events resulting from the command



24
25
26
27
28
29
30
31
32
33
# File 'lib/sequent/core/command_service.rb', line 24

def execute_commands(*commands)
  commands.each do |command|
    if command.respond_to?(:event_aggregate_id) && CurrentEvent.current
      command.event_aggregate_id = CurrentEvent.current.aggregate_id
      command.event_sequence_number = CurrentEvent.current.sequence_number
    end
  end
  commands.each { |command| command_queue.push(command) }
  process_commands
end

#remove_event_handler(clazz) ⇒ Object



35
36
37
# File 'lib/sequent/core/command_service.rb', line 35

def remove_event_handler(clazz)
  event_store.remove_event_handler(clazz)
end