File tree Expand file tree Collapse file tree 1 file changed +45
-0
lines changed Expand file tree Collapse file tree 1 file changed +45
-0
lines changed Original file line number Diff line number Diff line change
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 )
You can’t perform that action at this time.
0 commit comments