Skip to content
Snippets Groups Projects
Commit 8bfadfd0 authored by Dean Lovett's avatar Dean Lovett
Browse files

feat: added mechanism for reregistering the handlers

parent aac3a7d4
No related branches found
Tags 0.2.0
No related merge requests found
Pipeline #18987 failed
......@@ -7,8 +7,7 @@ module NexusCqrs
MultipleHandlers = Class.new(StandardError)
def initialize(middleware: nil)
@handlers =
ThreadSafe::Cache.new
@handlers = ThreadSafe::Cache.new
@middleware = middleware || Middleware::Builder.new
end
......@@ -29,6 +28,10 @@ module NexusCqrs
handlers
end
def clear_handlers
@handlers = ThreadSafe::Cache.new
end
attr_reader :handlers
private
......
module NexusCqrs
class CommandExecutor
# @param [NexusCqrs::CommandBus] command_bus
def initialize(command_bus)
@bus = command_bus
register_commands
end
# @param [NexusCqrs::BaseCommand] command
def execute(command)
@bus.call(command)
end
# @param [NexusCqrs::BaseCommandHandler] handler
def register_command(klass, handler)
@bus.register(klass, handler)
end
private
def reregister_handlers
return if @register_handlers.nil?
def register_commands
# TODO, Register Commands/Queries
@bus.clear_handlers
@register_handlers.call(self)
end
def configure_handlers(&block)
@register_handlers = block
@register_handlers.call(self)
end
end
end
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment