diff --git a/examples/di_demo2/demo.py b/examples/di_demo/demo.py similarity index 100% rename from examples/di_demo2/demo.py rename to examples/di_demo/demo.py diff --git a/examples/di_demo/example.py b/examples/di_demo/example.py deleted file mode 100644 index 8f4a4234..00000000 --- a/examples/di_demo/example.py +++ /dev/null @@ -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 diff --git a/examples/di_demo/example_di.py b/examples/di_demo/example_di.py index ddbbe14b..db85c237 100644 --- a/examples/di_demo/example_di.py +++ b/examples/di_demo/example_di.py @@ -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'))) diff --git a/examples/di_demo2/example_no_di.py b/examples/di_demo/example_no_di.py similarity index 100% rename from examples/di_demo2/example_no_di.py rename to examples/di_demo/example_no_di.py diff --git a/examples/di_demo2/test.py b/examples/di_demo/test.py similarity index 100% rename from examples/di_demo2/test.py rename to examples/di_demo/test.py diff --git a/examples/di_demo2/example_di.py b/examples/di_demo2/example_di.py deleted file mode 100644 index db85c237..00000000 --- a/examples/di_demo2/example_di.py +++ /dev/null @@ -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')))