Skip to content

Commit efc62e1

Browse files
committed
Defer to parent binder if it has an explicit binding
1 parent 1032e80 commit efc62e1

File tree

1 file changed

+11
-2
lines changed

1 file changed

+11
-2
lines changed

injector/__init__.py

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -365,10 +365,19 @@ class MultiBindProvider(ListOfProviders[List[T]]):
365365
def get(self, injector: 'Injector') -> List[T]:
366366
result: List[T] = []
367367
for binding in self._multi_bindings:
368-
scope_binding, _ = self._binder.get_binding(binding.scope)
368+
if (
369+
isinstance(binding.provider, ClassProvider)
370+
and binding.scope is NoScope
371+
and self._binder.parent
372+
and self._binder.parent.has_explicit_binding_for(binding.provider._cls)
373+
):
374+
parent_binding, _ = self._binder.parent.get_binding(binding.provider._cls)
375+
scope_binding, _ = self._binder.parent.get_binding(parent_binding.scope)
376+
else:
377+
scope_binding, _ = self._binder.get_binding(binding.scope)
369378
scope_instance: Scope = scope_binding.provider.get(injector)
370379
provider_instance = scope_instance.get(binding.interface, binding.provider)
371-
instances: List[T] = _ensure_iterable(provider_instance.get(injector))
380+
instances = _ensure_iterable(provider_instance.get(injector))
372381
result.extend(instances)
373382
return result
374383

0 commit comments

Comments
 (0)