File tree Expand file tree Collapse file tree 1 file changed +31
-1
lines changed Expand file tree Collapse file tree 1 file changed +31
-1
lines changed Original file line number Diff line number Diff line change @@ -254,13 +254,43 @@ To inject a container use special identifier ``<container>``:
254254 Making injections into modules and class attributes
255255---------------------------------------------------
256256
257- You can use wiring to make injections into modules and class attributes.
257+ You can use wiring to make injections into modules and class attributes. Both the classic marker
258+ syntax and the ``Annotated `` form are supported.
259+
260+ Classic marker syntax:
261+
262+ .. code-block :: python
263+
264+ service: Service = Provide[Container.service]
265+
266+ class Main :
267+ service: Service = Provide[Container.service]
268+
269+ Full example of the classic marker syntax:
258270
259271.. literalinclude :: ../examples/wiring/example_attribute.py
260272 :language: python
261273 :lines: 3-
262274 :emphasize-lines: 14,19
263275
276+ Annotated form (Python 3.9+):
277+
278+ .. code-block :: python
279+
280+ from typing import Annotated
281+
282+ service: Annotated[Service, Provide[Container.service]]
283+
284+ class Main :
285+ service: Annotated[Service, Provide[Container.service]]
286+
287+ Full example of the annotated form:
288+
289+ .. literalinclude :: ../examples/wiring/example_attribute_annotated.py
290+ :language: python
291+ :lines: 3-
292+ :emphasize-lines: 16,21
293+
264294You could also use string identifiers to avoid a dependency on a container:
265295
266296.. code-block :: python
You can’t perform that action at this time.
0 commit comments