mirror of
https://github.com/ets-labs/python-dependency-injector.git
synced 2024-12-04 23:44:05 +03:00
32 lines
578 B
Python
32 lines
578 B
Python
"""Container overriding example."""
|
|
|
|
from dependency_injector import containers, providers
|
|
|
|
|
|
class Service:
|
|
...
|
|
|
|
|
|
class ServiceStub:
|
|
...
|
|
|
|
|
|
class Container(containers.DeclarativeContainer):
|
|
|
|
service = providers.Factory(Service)
|
|
|
|
|
|
class OverridingContainer(containers.DeclarativeContainer):
|
|
|
|
service = providers.Factory(ServiceStub)
|
|
|
|
|
|
if __name__ == "__main__":
|
|
container = Container()
|
|
overriding_container = OverridingContainer()
|
|
|
|
container.override(overriding_container)
|
|
|
|
service = container.service()
|
|
assert isinstance(service, ServiceStub)
|