python-dependency-injector/examples/ioc_di_demos/ioc_container_example.py

18 lines
416 B
Python
Raw Normal View History

2016-04-01 10:47:09 +03:00
"""The Code, that uses IoC container."""
2016-03-29 20:17:12 +03:00
2016-04-04 19:12:21 +03:00
from dependency_injector import catalogs, providers
2016-04-01 10:47:09 +03:00
2016-04-04 19:12:21 +03:00
from ioc_example import Service, Client
2016-03-29 20:17:12 +03:00
class Components(catalogs.DeclarativeCatalog):
"""Components catalog."""
service = providers.Factory(Service)
2016-04-01 18:00:58 +03:00
2016-03-31 21:13:28 +03:00
client = providers.Factory(Client, service=service)
2016-03-29 20:17:12 +03:00
if __name__ == '__main__':
2016-03-30 11:45:41 +03:00
client = Components.client() # Application creates Client's instance