We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 8bf9ed0 commit 19600d9Copy full SHA for 19600d9
examples/wiring/example_attribute_annotated.py
@@ -0,0 +1,29 @@
1
+"""Wiring attribute example with Annotated."""
2
+
3
+from typing import Annotated
4
5
+from dependency_injector import containers, providers
6
+from dependency_injector.wiring import Provide
7
8
9
+class Service:
10
+ ...
11
12
13
+class Container(containers.DeclarativeContainer):
14
+ service = providers.Factory(Service)
15
16
17
+service: Annotated[Service, Provide[Container.service]]
18
19
20
+class Main:
21
+ service: Annotated[Service, Provide[Container.service]]
22
23
24
+if __name__ == "__main__":
25
+ container = Container()
26
+ container.wire(modules=[__name__])
27
28
+ assert isinstance(service, Service)
29
+ assert isinstance(Main.service, Service)
0 commit comments