2020-08-16 05:09:41 +03:00
|
|
|
"""Dynamic container example."""
|
2016-06-06 11:26:53 +03:00
|
|
|
|
2020-08-16 05:09:41 +03:00
|
|
|
from dependency_injector import containers, providers
|
2016-06-06 11:26:53 +03:00
|
|
|
|
|
|
|
|
2020-08-16 05:09:41 +03:00
|
|
|
if __name__ == '__main__':
|
|
|
|
container = containers.DynamicContainer()
|
|
|
|
container.factory1 = providers.Factory(object)
|
|
|
|
container.factory2 = providers.Factory(object)
|
2016-06-06 11:26:53 +03:00
|
|
|
|
2020-08-16 05:09:41 +03:00
|
|
|
object1 = container.factory1()
|
|
|
|
object2 = container.factory2()
|
2016-06-06 11:26:53 +03:00
|
|
|
|
2020-08-16 05:09:41 +03:00
|
|
|
print(container.providers)
|
|
|
|
# {
|
|
|
|
# 'factory1': <dependency_injector.providers.Factory(...),
|
|
|
|
# 'factory2': <dependency_injector.providers.Factory(...),
|
|
|
|
# }
|