Skip to content

Commit 8e88838

Browse files
committed
handle_event and handle_command call out to new di method [messagebus_handlers_change]
1 parent dc673a5 commit 8e88838

1 file changed

Lines changed: 17 additions & 17 deletions

File tree

src/allocation/service_layer/messagebus.py

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
Message = Union[commands.Command, events.Event]
1515

1616

17+
1718
class MessageBus:
1819

1920
def __init__(
@@ -34,24 +35,23 @@ def handle(self, message: Message):
3435
raise Exception(f'{message} was not an Event or Command')
3536

3637

37-
def handle_event(event: events.Event, uow: unit_of_work.AbstractUnitOfWork):
38-
for handler in EVENT_HANDLERS[type(event)]:
39-
try:
40-
logger.debug('handling event %s with handler %s', event, handler)
41-
handler(event, uow=uow)
42-
except:
43-
logger.exception('Exception handling event %s', event)
44-
continue
45-
38+
def handle_event(self, event: events.Event):
39+
for handler in EVENT_HANDLERS[type(event)]:
40+
try:
41+
logger.debug('handling event %s with handler %s', event, handler)
42+
self.call_handler_with_dependencies(handler, event)
43+
except:
44+
logger.exception('Exception handling event %s', event)
45+
continue
4646

47-
def handle_command(command, uow: unit_of_work.AbstractUnitOfWork):
48-
logger.debug('handling command %s', command)
49-
try:
50-
handler = COMMAND_HANDLERS[type(command)]
51-
handler(command, uow=uow)
52-
except Exception:
53-
logger.exception('Exception handling command %s', command)
54-
raise
47+
def handle_command(self, command: commands.Command):
48+
logger.debug('handling command %s', command)
49+
try:
50+
handler = COMMAND_HANDLERS[type(command)]
51+
self.call_handler_with_dependencies(handler, command)
52+
except Exception:
53+
logger.exception('Exception handling command %s', command)
54+
raise
5555

5656

5757
EVENT_HANDLERS = {

0 commit comments

Comments
 (0)