Can't override base class dependencies container with dependency built by callable
See original GitHub issueHere is another tricky one I stumbled on –
from dependency_injector import providers, containers
class X(containers.DeclarativeContainer):
foo = providers.Dependency(instance_of=str)
def build_x():
return X(foo="1")
class A(containers.DeclarativeContainer):
x = providers.DependenciesContainer(**X.providers)
y = x.foo
@containers.copy(A)
class B1(A):
some_x = providers.Callable(build_x)
x = some_x.provided
b1 = B1()
print(b1.y()) # fails with "Dependency is not defined"
I also can’t get it to work by repeating x definition and overriding:
@containers.copy(A)
class B2(A):
some_x = providers.Callable(build_x)
x = providers.DependenciesContainer(**X.providers)
x.override(some_x.provided)
Gives TypeError: 'builtin_function_or_method' object is not iterable
on module load.
Issue Analytics
- State:
- Created 3 years ago
- Comments:5 (4 by maintainers)
Top Results From Across the Web
Implicitly injecting dependency in Base class while derived ...
No, unity is unable to do so. Actually, there's not a single container who can do so. A constructor is there to instantiate...
Read more >Classes as Dependencies - FastAPI
The key factor is that a dependency should be a "callable". A "callable" in Python is anything that Python can "call" like a...
Read more >Issue #336 · ets-labs/python-dependency-injector - GitHub
I am trying to create a container that optionally takes a dependency, and otherwise provides a value derived from another provider.
Read more >Handling Dependency Injection in Inherited Classes
Conclusion. In this post I have described a simple method for managing dependency injection in inherited classes, by creating a dependency ...
Read more >Service Container - The PHP Framework For Web Artisans
Dependency injection is a fancy phrase that essentially means this: class dependencies are "injected" into the class via the constructor or, in some...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Fixed in
4.11.1
. It’s been publishing on PyPI right now and will be ready as soon as https://github.com/ets-labs/python-dependency-injector/actions/runs/515305692 is done. Btw, it’s a new CD pipeline on Github Actions.Hey @shaunc ,
Here is a way to make it work:
PS: My apologies it took so long to answer. Was overwhelmed with other stuff.