2021-02-15 02:51:55 +03:00
|
|
|
.. _reset-container-singletons:
|
|
|
|
|
2021-02-06 01:14:10 +03:00
|
|
|
Reset container singletons
|
|
|
|
--------------------------
|
|
|
|
|
|
|
|
To reset all container singletons use method ``.reset_singletons()``.
|
|
|
|
|
|
|
|
.. literalinclude:: ../../examples/containers/reset_singletons.py
|
|
|
|
:language: python
|
|
|
|
:lines: 3-
|
|
|
|
:emphasize-lines: 16
|
|
|
|
|
|
|
|
Method ``.reset_singletons()`` also resets singletons in sub-containers: ``providers.Container`` and
|
|
|
|
``providers.DependenciesContainer.``
|
|
|
|
|
|
|
|
.. literalinclude:: ../../examples/containers/reset_singletons_subcontainers.py
|
|
|
|
:language: python
|
|
|
|
:lines: 3-
|
|
|
|
:emphasize-lines: 21
|
|
|
|
|
2021-03-03 16:28:10 +03:00
|
|
|
You can use ``.reset_singletons()`` method with a context manager. Singletons will be reset on
|
|
|
|
both entering and exiting a context.
|
|
|
|
|
|
|
|
.. literalinclude:: ../../examples/containers/reset_singletons_with.py
|
|
|
|
:language: python
|
|
|
|
:lines: 3-
|
|
|
|
:emphasize-lines: 14-15
|
|
|
|
|
2021-02-15 02:51:55 +03:00
|
|
|
See also: :ref:`singleton-provider`.
|
|
|
|
|
2021-02-06 01:14:10 +03:00
|
|
|
.. disqus::
|