Remove old di demo

This commit is contained in:
Roman Mogylatov 2020-09-03 23:21:09 -04:00
parent f0004c805f
commit 0a10f32233
6 changed files with 11 additions and 46 deletions

View File

@ -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

View File

@ -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:
"""The Service."""
class Client:
"""The Client that uses the Service."""
def __init__(self, service): # The Service is injected into the Client
"""Initialize the Client."""
self.service = service
def __init__(self, api_client: ApiClient):
self.api_client = api_client
if __name__ == '__main__':
service = Service() # Application creates the Service
client = Client(service) # and inject the Service into the Client
service = Service(ApiClient(os.getenv('API_KEY'), os.getenv('TIMEOUT')))

View File

@ -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')))