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

24 lines
538 B
Python
Raw Normal View History

2020-08-14 23:27:17 +03:00
"""Declarative container example."""
2016-05-29 22:06:02 +03:00
2020-08-14 23:27:17 +03:00
from dependency_injector import containers, providers
2016-05-29 22:06:02 +03:00
class Container(containers.DeclarativeContainer):
factory1 = providers.Factory(object)
factory2 = providers.Factory(object)
2016-11-15 15:26:40 +03:00
if __name__ == '__main__':
container = Container()
2016-05-29 22:06:02 +03:00
object1 = container.factory1()
object2 = container.factory2()
2020-08-14 23:27:17 +03:00
print(container.providers)
# {
# 'factory1': <dependency_injector.providers.Factory(...),
# 'factory2': <dependency_injector.providers.Factory(...),
# }