mirror of
https://github.com/ets-labs/python-dependency-injector.git
synced 2025-01-30 19:24:31 +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:
|
||||
"""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')))
|
||||
|
|
|
@ -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