Skip to content

Commit 257276c

Browse files
committed
experiment with nonmagic DI zzzz [nomagic_di]
1 parent 15e0dc2 commit 257276c

File tree

1 file changed

+16
-8
lines changed

1 file changed

+16
-8
lines changed

src/allocation/bootstrap.py

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import inspect
22
from typing import Callable
3+
from allocation.domain import commands, events
34
from allocation.adapters import email, orm, redis_eventpublisher
45
from allocation.service_layer import handlers, messagebus, unit_of_work
56

@@ -14,17 +15,24 @@ def bootstrap(
1415
if start_orm:
1516
orm.start_mappers()
1617

17-
dependencies = {"uow": uow, "send_mail": send_mail, "publish": publish}
1818
injected_event_handlers = {
19-
event_type: [
20-
inject_dependencies(handler, dependencies)
21-
for handler in event_handlers
22-
]
23-
for event_type, event_handlers in handlers.EVENT_HANDLERS.items()
19+
events.Allocated: [
20+
lambda e: handlers.publish_allocated_event(e, publish),
21+
lambda e: handlers.add_allocation_to_read_model(e, uow),
22+
],
23+
events.Deallocated: [
24+
lambda e: handlers.remove_allocation_from_read_model(e, uow),
25+
lambda e: handlers.reallocate(e, uow),
26+
],
27+
events.OutOfStock: [
28+
lambda e: handlers.send_out_of_stock_notification(e, send_mail)
29+
],
2430
}
2531
injected_command_handlers = {
26-
command_type: inject_dependencies(handler, dependencies)
27-
for command_type, handler in handlers.COMMAND_HANDLERS.items()
32+
commands.Allocate: lambda c: handlers.allocate(c, uow),
33+
commands.CreateBatch: lambda c: handlers.add_batch(c, uow),
34+
commands.ChangeBatchQuantity: \
35+
lambda c: handlers.change_batch_quantity(c, uow),
2836
}
2937

3038
return messagebus.MessageBus(

0 commit comments

Comments
 (0)