provide default for a dependencies container from another dependencies container
See original GitHub issueHere is a case that is sort of a mix of other recipes you have provided: I would like to provide a default value for a dependencies container by taking it from another dependencies container:
from dependency_injector import containers, providers
class PV(containers.DeclarativeContainer):
foo = providers.Object("foo")
PV_SPEC = dict(foo = providers.Dependency(instance_of = str))
class HasPV(containers.DeclarativeContainer):
pv = providers.DependenciesContainer(**PV_SPEC)
HasPVSpec = dict(pv = providers.DependenciesContainer(**PV_SPEC))
class HasPV2(containers.DeclarativeContainer):
has_pv = providers.DependenciesContainer(**HasPVSpec)
pv = providers.DependenciesContainer(**PV_SPEC)
pv.override(has_pv.pv)
This gives:
src/dependency_injector/providers.pyx in dependency_injector.providers.DependenciesContainer.override()
src/dependency_injector/providers.pyx in dependency_injector.providers.DependenciesContainer._override_providers()
src/dependency_injector/providers.pyx in dependency_injector.providers.Provider.override()
Error: Provider <dependency_injector.providers.Dependency(<class 'str'>) at 0x7fda702c96d0> could not be overridden with itself
Issue Analytics
- State:
- Created 3 years ago
- Comments:5 (3 by maintainers)
Top Results From Across the Web
Providing fallbacks / defaults for dependencies when using ...
1 Answer 1 · By constructing a new MyNewDefaultService() dependency in your consumer class, you are coupling to a concrete service class, in ......
Read more >How To Manage Docker Dependencies With Ease
You can use it to create your application in a first “build” container and inject the results in a second container, without the...
Read more >Control startup and shutdown order in Compose
Compose always starts and stops containers in dependency order, where dependencies are determined by depends_on , links , volumes_from , and network_mode: ...
Read more >Container copying - Dependency Injector
Base container often keeps default dependencies while derived containers define overriding providers. Without @containers.copy() decorator, overridden providers ...
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 >
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 Free
Top 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
Seems #357 feature helps to resolve this one too:
What do you think?
Good, thanks!