1414Message = Union [commands .Command , events .Event ]
1515
1616
17+
1718class 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
5757EVENT_HANDLERS = {
0 commit comments