From 0a10f32233dfa8435bc32e91333c524893fcfde5 Mon Sep 17 00:00:00 2001 From: Roman Mogylatov Date: Thu, 3 Sep 2020 23:21:09 -0400 Subject: [PATCH] Remove old di demo --- examples/{di_demo2 => di_demo}/demo.py | 0 examples/di_demo/example.py | 17 -------------- examples/di_demo/example_di.py | 22 +++++++++---------- .../{di_demo2 => di_demo}/example_no_di.py | 0 examples/{di_demo2 => di_demo}/test.py | 0 examples/di_demo2/example_di.py | 18 --------------- 6 files changed, 11 insertions(+), 46 deletions(-) rename examples/{di_demo2 => di_demo}/demo.py (100%) delete mode 100644 examples/di_demo/example.py rename examples/{di_demo2 => di_demo}/example_no_di.py (100%) rename examples/{di_demo2 => di_demo}/test.py (100%) delete mode 100644 examples/di_demo2/example_di.py 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')))