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