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

20 lines
482 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:16:20 +03:00
from dependency_injector import catalogs
from dependency_injector import providers
2016-04-01 10:47:09 +03:00
2016-04-04 19:16:20 +03:00
from ioc_example import Service
from ioc_example import Client
2016-03-29 20:17:12 +03:00
class Components(catalogs.DeclarativeCatalog):
2016-04-05 00:25:18 +03:00
"""Catalog of component providers."""
2016-03-29 20:17:12 +03:00
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