Skip to content

Commit dc673a5

Browse files
committed
start modifying messagebus to do di [messagebus_as_class]
1 parent 2db57ff commit dc673a5

1 file changed

Lines changed: 19 additions & 7 deletions

File tree

‎src/allocation/service_layer/messagebus.py‎

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
# pylint: disable=bare-except
22
from __future__ import annotations
33
import logging
4+
import inspect
45
from typing import List, Dict, Callable, Type, Union, TYPE_CHECKING
56
from allocation.domain import commands, events
67
from . import handlers
@@ -13,13 +14,24 @@
1314
Message = Union[commands.Command, events.Event]
1415

1516

16-
def handle(message: Message, uow: unit_of_work.AbstractUnitOfWork):
17-
if isinstance(message, events.Event):
18-
handle_event(message, uow)
19-
elif isinstance(message, commands.Command):
20-
handle_command(message, uow)
21-
else:
22-
raise Exception(f'{message} was not an Event or Command')
17+
class MessageBus:
18+
19+
def __init__(
20+
self,
21+
uow: unit_of_work.AbstractUnitOfWork,
22+
send_mail: Callable,
23+
publish: Callable,
24+
):
25+
self.uow = uow
26+
self.dependencies = dict(uow=uow, send_mail=send_mail, publish=publish)
27+
28+
def handle(self, message: Message):
29+
if isinstance(message, events.Event):
30+
self.handle_event(message)
31+
elif isinstance(message, commands.Command):
32+
self.handle_command(message)
33+
else:
34+
raise Exception(f'{message} was not an Event or Command')
2335

2436

2537
def handle_event(event: events.Event, uow: unit_of_work.AbstractUnitOfWork):

0 commit comments

Comments
 (0)