You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Create unbound @singleton instances in the parent injector (#216)
This change introduces consistency to how instances for unbound
classes decorated with a `@singleton` are shared among parent/child
injectors, when auto-binding is enabled.
Classes decorated with `@singleton`, that have not been explicitly
bound, are now created by and bound to the parent injector closest
to the root where all dependencies are fulfilled.
The behavior was like this before, but only when the parent injector
had created the singleton instance (and its implicit binding) before
the child injector. This allows sharing singletons between child
injectors without creating them on the parent injector first.
Copy file name to clipboardExpand all lines: docs/scopes.rst
+2Lines changed: 2 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -24,6 +24,8 @@ A (redundant) example showing all three methods::
24
24
def provide_thing(self) -> Thing:
25
25
return Thing()
26
26
27
+
If using hierarchies of injectors, classes decorated with `@singleton` will be created by and bound to the parent/ancestor injector closest to the root that can provide all of its dependencies.
0 commit comments