mirror of
https://github.com/ets-labs/python-dependency-injector.git
synced 2025-02-07 07:00:49 +03:00
Remove old di demo
This commit is contained in:
parent
f0004c805f
commit
0a10f32233
|
@ -1,17 +0,0 @@
|
||||||
"""The Code."""
|
|
||||||
|
|
||||||
|
|
||||||
class Service:
|
|
||||||
"""The Service."""
|
|
||||||
|
|
||||||
|
|
||||||
class Client:
|
|
||||||
"""The Client that uses the Service."""
|
|
||||||
|
|
||||||
def __init__(self):
|
|
||||||
"""Initialize the Client."""
|
|
||||||
self.service = Service() # The Service is created by the Client
|
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
|
||||||
client = Client() # Application creates the Client
|
|
|
@ -1,18 +1,18 @@
|
||||||
"""The Code that demonstrates dependency injection pattern."""
|
import os
|
||||||
|
|
||||||
|
|
||||||
|
class ApiClient:
|
||||||
|
|
||||||
|
def __init__(self, api_key: str, timeout: int):
|
||||||
|
self.api_key = api_key
|
||||||
|
self.timeout = timeout
|
||||||
|
|
||||||
|
|
||||||
class Service:
|
class Service:
|
||||||
"""The Service."""
|
|
||||||
|
|
||||||
|
def __init__(self, api_client: ApiClient):
|
||||||
class Client:
|
self.api_client = api_client
|
||||||
"""The Client that uses the Service."""
|
|
||||||
|
|
||||||
def __init__(self, service): # The Service is injected into the Client
|
|
||||||
"""Initialize the Client."""
|
|
||||||
self.service = service
|
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
service = Service() # Application creates the Service
|
service = Service(ApiClient(os.getenv('API_KEY'), os.getenv('TIMEOUT')))
|
||||||
client = Client(service) # and inject the Service into the Client
|
|
||||||
|
|
|
@ -1,18 +0,0 @@
|
||||||
import os
|
|
||||||
|
|
||||||
|
|
||||||
class ApiClient:
|
|
||||||
|
|
||||||
def __init__(self, api_key: str, timeout: int):
|
|
||||||
self.api_key = api_key
|
|
||||||
self.timeout = timeout
|
|
||||||
|
|
||||||
|
|
||||||
class Service:
|
|
||||||
|
|
||||||
def __init__(self, api_client: ApiClient):
|
|
||||||
self.api_client = api_client
|
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
|
||||||
service = Service(ApiClient(os.getenv('API_KEY'), os.getenv('TIMEOUT')))
|
|
Loading…
Reference in New Issue
Block a user