Providing dependencies across more than one level of inheritance
See original GitHub issueI have a derived chain of containers (say, C1 -> C2 -> C3
). I want to instantiate C3
with a dependency for C1
, which is then used (directly and indirectly) in the derived containers.
In fact, I have found a way to do it, but it is ugly:
class C1(containers.DeclarativeContainer):
a1 = providers.Dependency(instance_of=str)
class C2(C1):
a1_ = C1.a1
a1 = providers.Dependency(instance_of=str)
a1_.override(a1)
a2 = providers.Callable(C1.a1)
class C3(C2):
a3 = providers.Callable(C2.a1)
c3 = C3(a1="foo")
print("c3", c3.a3()) # prints "foo"
I can’t seem to get it to work without the intermediate redefinition of a1 … is this a bug? E.g. if I don’t have that and try to instantiate C3(a1="foo")
I get an error:
AttributeError: 'DynamicContainer' object has no attribute 'a1'
(I tried fiddling with @containers.copy()
as well, unsuccessfully).
Issue Analytics
- State:
- Created 3 years ago
- Comments:9 (7 by maintainers)
Top Results From Across the Web
Depedency version inheritance more than one level
I've given all dependent jars in dependencyManagement of Project A POM and version of those jars are maintained using property project.version.
Read more >Handling Dependency Injection in Inherited Classes
In this post I have described a simple method for managing dependency injection in inherited classes, by creating a dependency aggregate class ......
Read more >Inheritance Relationship - an overview | ScienceDirect Topics
We speak of single inheritance when the inheritance hierarchy is arranged in a tree, that is, if a class has only one direct...
Read more >Maven: The Complete Reference - 3.5. Project Relationships
When Maven inherits dependencies, it will add dependencies of child projects to the dependencies defined in parent projects. You can use this feature...
Read more >Hierarchical injectors - Angular
With hierarchical dependency injection, you can isolate sections of the application and give them their own private dependencies not shared with the rest...
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
Hey @shaunc , that’s good example, I’ll take a look.
Closing the issue. Re-open if needed.