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