python-dependency-injector/examples/containers/dynamic.py

19 lines
518 B
Python
Raw Permalink Normal View History

"""Dynamic container example."""
from dependency_injector import containers, providers
2021-09-30 22:16:17 +03:00
if __name__ == "__main__":
container = containers.DynamicContainer()
container.factory1 = providers.Factory(object)
container.factory2 = providers.Factory(object)
object1 = container.factory1()
object2 = container.factory2()
print(container.providers)
# {
2021-09-30 22:16:17 +03:00
# "factory1": <dependency_injector.providers.Factory(...),
# "factory2": <dependency_injector.providers.Factory(...),
# }