@@ -20,13 +20,12 @@ returns it on the rest of the calls.
2020 :language: python
2121 :lines: 3-
2222
23- ``Singleton `` provider handles an injection of the dependencies the same way like a
24- :ref: `factory-provider `.
23+ ``Singleton `` provider handles dependencies injection the same way like a :ref: `factory-provider `.
2524
2625.. note ::
2726
28- ``Singleton `` provider does dependencies injection only when creates the object. When the object
29- is created and memorized ``Singleton `` provider just returns it without applying the injections.
27+ ``Singleton `` provider makes dependencies injection only when creates an object. When an object
28+ is created and memorized ``Singleton `` provider just returns it without applying injections.
3029
3130Specialization of the provided type and abstract singletons work the same like like for the
3231factories:
@@ -56,6 +55,21 @@ provider.
5655 Resetting of the memorized object clears the reference to it. Further object's lifecycle is
5756 managed by the garbage collector.
5857
58+ You can use ``.reset() `` method with a context manager. Memorized instance will be reset on
59+ both entering and exiting a context.
60+
61+ .. literalinclude :: ../../examples/providers/singleton_resetting_with.py
62+ :language: python
63+ :lines: 3-
64+ :emphasize-lines: 18-19
65+
66+ Context manager ``.reset() `` returns resetting singleton provider. You can use it for aliasing.
67+
68+ .. code-block :: python
69+
70+ with container.user_service.reset() as user_service:
71+ ...
72+
5973 Method ``.reset() `` resets only current provider. To reset all dependent singleton providers
6074call ``.full_reset() `` method.
6175
@@ -64,6 +78,13 @@ call ``.full_reset()`` method.
6478 :lines: 3-
6579 :emphasize-lines: 25
6680
81+ Method ``.full_reset() `` supports context manager interface like ``.reset() `` does.
82+
83+ .. code-block :: python
84+
85+ with container.user_service.full_reset() as user_service:
86+ ...
87+
6788 See also: :ref: `reset-container-singletons `.
6889
6990Using singleton with multiple threads
0 commit comments