Class: Sequent::Core::CommandService
- Inherits:
-
Object
- Object
- Sequent::Core::CommandService
- Defined in:
- lib/sequent/core/command_service.rb
Overview
Single point in the application to get something done in Sequent. The CommandService handles all subclasses Sequent::Core::BaseCommand. Most common use is to subclass ‘Sequent::Command`.
The CommandService is available via the shortcut method ‘Sequent.command_service`
To use the CommandService please use:
Sequent.command_service.execute_commands(...)
Instance Method Summary collapse
-
#execute_commands(*commands) ⇒ Object
Executes the given commands in a single transactional block as implemented by the
transaction_provider
. - #remove_event_handler(clazz) ⇒ Object
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:
-
Validate command
-
Call Sequent::CommandHandler’s listening to the given Command
-
Store and publish Events
-
Any new Command’s (from e.g. workflows) are queued for processing in the same transaction
At the end the transaction is committed and the AggregateRepository’s Unit of Work is cleared.
32 33 34 35 36 37 38 39 40 41 |
# File 'lib/sequent/core/command_service.rb', line 32 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
43 44 45 46 |
# File 'lib/sequent/core/command_service.rb', line 43 def remove_event_handler(clazz) warn '[DEPRECATION] `remove_event_handler` is deprecated' event_store.remove_event_handler(clazz) end |