-
-
Notifications
You must be signed in to change notification settings - Fork 326
provide default for a dependencies container from another dependencies container #356
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
Also tried: ...
HasPVSpec = dict(pv = providers.Dependency(instance_of=containers.DynamicContainer))
class HasPV2(containers.DeclarativeContainer):
has_pv = providers.DependenciesContainer(**HasPVSpec)
pv = providers.DependenciesContainer(**PV_SPEC)
pv.override(has_pv.pv.provided) Without the "provided" this gives Update -- sure would be nice if |
Didn't get to that one today. Will take a look tomorrow. |
Seems #357 feature helps to resolve this one too: from dependency_injector import containers, providers
class PV(containers.DeclarativeContainer):
foo = providers.Object('foo')
class HasPV(containers.DeclarativeContainer):
pv = providers.DependenciesContainer(**PV.dependencies)
class HasPV2(containers.DeclarativeContainer):
has_pv = providers.DependenciesContainer(**HasPV.dependencies)
pv = providers.DependenciesContainer(**PV.dependencies)
pv.override(has_pv.pv)
if __name__ == '__main__':
haspv2 = HasPV2(pv=PV(foo='bar'))
print(haspv2.pv.foo()) # prints: bar What do you think? |
Looks good too! -- Thanks! |
Good, thanks! |
Here 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:
This gives:
The text was updated successfully, but these errors were encountered: