mirror of
https://github.com/ets-labs/python-dependency-injector.git
synced 2025-02-16 19:40:59 +03:00
* Add implementation * Add Self provider tests * Add container tests * Remove ellipsis from tests to make them pass on Python 2 * Add tests * Add docs * Improve traverse() typing stubs * Update changelog
21 lines
624 B
ReStructuredText
21 lines
624 B
ReStructuredText
Injecting container "self"
|
|
==========================
|
|
|
|
You can inject container "self" into container providers.
|
|
|
|
.. literalinclude:: ../../examples/containers/inject_self.py
|
|
:language: python
|
|
:lines: 3-
|
|
:emphasize-lines: 20, 26
|
|
|
|
To inject container "self" you need to define ``Self`` provider. Container can have only one ``Self`` provider.
|
|
|
|
Usually you will use name ``__self__``.
|
|
You can also use different name. When you use different name container will also reference
|
|
defined ``Self`` provider in ``.__self__`` attribute.
|
|
|
|
Provider ``Self`` is not listed in container ``.providers`` attributes.
|
|
|
|
.. disqus::
|
|
|