22
33import injection
44
5+ from cq ._core .dispatcher .base import Dispatcher
56from cq ._core .dispatcher .bus import Bus , SimpleBus , TaskBus
67from cq ._core .handler import (
78 HandlerDecorator ,
1516Event = object
1617Query = object
1718
18- type CommandBus [T ] = Bus [Command , T ]
19- type EventBus = Bus [Event , None ]
20- type QueryBus [T ] = Bus [Query , T ]
19+ type CommandBus [T ] = Dispatcher [Command , T ]
20+ type EventBus = Dispatcher [Event , None ]
21+ type QueryBus [T ] = Dispatcher [Query , T ]
2122
2223AnyCommandBus = CommandBus [Any ]
2324
3334)
3435
3536
36- @injection .injectable (inject = False , mode = "fallback" )
37- def new_command_bus (* , threadsafe : bool | None = None ) -> CommandBus : # type: ignore[type-arg]
37+ def new_command_bus (* , threadsafe : bool | None = None ) -> Bus [Command , Any ]:
3838 bus = SimpleBus (command_handler .manager )
3939 transaction_scope_middleware = InjectionScopeMiddleware (
4040 CQScope .TRANSACTION ,
@@ -45,11 +45,27 @@ def new_command_bus(*, threadsafe: bool | None = None) -> CommandBus: # type: i
4545 return bus
4646
4747
48- @injection .injectable (inject = False , mode = "fallback" )
49- def new_event_bus () -> EventBus :
48+ def new_event_bus () -> Bus [Event , None ]:
5049 return TaskBus (event_handler .manager )
5150
5251
53- @injection .injectable (inject = False , mode = "fallback" )
54- def new_query_bus () -> QueryBus : # type: ignore[type-arg]
52+ def new_query_bus () -> Bus [Query , Any ]:
5553 return SimpleBus (query_handler .manager )
54+
55+
56+ @injection .injectable (inject = False , mode = "fallback" )
57+ def _ () -> CommandBus : # type: ignore[type-arg]
58+ return new_command_bus ()
59+
60+
61+ @injection .injectable (inject = False , mode = "fallback" )
62+ def _ () -> EventBus :
63+ return new_event_bus ()
64+
65+
66+ @injection .injectable (inject = False , mode = "fallback" )
67+ def _ () -> QueryBus : # type: ignore[type-arg]
68+ return new_query_bus ()
69+
70+
71+ del _
0 commit comments