Skip to content

Commit 983b891

Browse files
committed
Revert "experiment with nonmagic DI zzzz"
This reverts commit f42b193857eec8560443767de9fd7ada9f2acb96.
1 parent 0bcc82d commit 983b891

File tree

1 file changed

+8
-16
lines changed

1 file changed

+8
-16
lines changed

src/allocation/bootstrap.py

Lines changed: 8 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1+
import inspect
12
from typing import Callable
2-
from allocation.domain import commands, events
33
from allocation.adapters import email, orm, redis_eventpublisher
44
from allocation.service_layer import handlers, messagebus, unit_of_work
55

@@ -14,25 +14,17 @@ def bootstrap(
1414
if start_orm:
1515
orm.start_mappers()
1616

17+
dependencies = {'uow': uow, 'send_mail': send_mail, 'publish': publish}
1718
injected_event_handlers = {
18-
events.Allocated: [
19-
lambda e: handlers.publish_allocated_event(e, publish),
20-
lambda e: handlers.add_allocation_to_read_model(e, uow),
21-
],
22-
events.Deallocated: [
23-
lambda e: handlers.remove_allocation_from_read_model(e, uow),
24-
lambda e: handlers.reallocate(e, uow),
25-
],
26-
events.OutOfStock: [
27-
lambda e: handlers.send_out_of_stock_notification(e, send_mail)
19+
event_type: [
20+
inject_dependencies(handler, dependencies)
21+
for handler in event_handlers
2822
]
23+
for event_type, event_handlers in handlers.EVENT_HANDLERS.items()
2924
}
3025
injected_command_handlers = {
31-
commands.Allocate: lambda c: handlers.allocate(c, uow),
32-
commands.CreateBatch: \
33-
lambda c: handlers.add_batch(c, uow),
34-
commands.ChangeBatchQuantity: \
35-
lambda c: handlers.change_batch_quantity(c, uow),
26+
command_type: inject_dependencies(handler, dependencies)
27+
for command_type, handler in handlers.COMMAND_HANDLERS.items()
3628
}
3729

3830
return messagebus.MessageBus(

0 commit comments

Comments
 (0)