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