Skip to content

Commit c15fc27

Browse files
committed
Add example
1 parent a72f3c5 commit c15fc27

File tree

1 file changed

+45
-0
lines changed

1 file changed

+45
-0
lines changed
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
"""`FactoryAggregate` provider with non-string keys example."""
2+
3+
from dependency_injector import containers, providers
4+
5+
6+
class Command:
7+
...
8+
9+
10+
class CommandA(Command):
11+
...
12+
13+
14+
class CommandB(Command):
15+
...
16+
17+
18+
class Handler:
19+
...
20+
21+
22+
class HandlerA(Handler):
23+
...
24+
25+
26+
class HandlerB(Handler):
27+
...
28+
29+
30+
class Container(containers.DeclarativeContainer):
31+
32+
handler_factory = providers.FactoryAggregate({
33+
CommandA: providers.Factory(HandlerA),
34+
CommandB: providers.Factory(HandlerB),
35+
})
36+
37+
38+
if __name__ == "__main__":
39+
container = Container()
40+
41+
handler_a = container.handler_factory(CommandA)
42+
handler_b = container.handler_factory(CommandB)
43+
44+
assert isinstance(handler_a, HandlerA)
45+
assert isinstance(handler_b, HandlerB)

0 commit comments

Comments
 (0)