mirror of
https://github.com/ets-labs/python-dependency-injector.git
synced 2024-11-22 17:47:02 +03:00
Update di example
This commit is contained in:
parent
08b00d71d4
commit
4e00a70834
|
@ -8,13 +8,10 @@ class Components(catalogs.DeclarativeCatalog):
|
||||||
"""Components catalog."""
|
"""Components catalog."""
|
||||||
|
|
||||||
service = providers.Factory(Service)
|
service = providers.Factory(Service)
|
||||||
""":type: providers.Factory -> Service"""
|
|
||||||
|
|
||||||
client = providers.Factory(Client,
|
client = providers.Factory(Client,
|
||||||
service=service)
|
service=service)
|
||||||
""":type: providers.Factory -> Client"""
|
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
# Application creates Client's instance using its provider
|
client = Components.client() # Application creates Client's instance
|
||||||
client = Components.client() # equivalent of Client(service=Service())
|
|
||||||
|
|
|
@ -14,5 +14,4 @@ class Client(object):
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
# Application just creates Client's instance
|
client = Client() # Application creates Client's instance
|
||||||
client = Client()
|
|
||||||
|
|
|
@ -14,8 +14,5 @@ class Client(object):
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
# Application creates Service instance
|
service = Service() # Application creates Service instance
|
||||||
service = Service()
|
client = Client(service) # and inject Service instance into the Client
|
||||||
|
|
||||||
# and inject Service instance into the Client
|
|
||||||
client = Client(service)
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user