Created
August 31, 2020 23:57
-
-
Save lastlegion/43d46d4e148dcfef02ea081887736401 to your computer and use it in GitHub Desktop.
Dependency injection example 1
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Repository: | |
def __init__(self): | |
self.db = os.getenv('dbname') | |
def get_data(self): | |
return 'Hello World' | |
class Service: | |
def __init__(self): | |
self.repository = Repository() | |
def process(self): | |
return self.dal.get_data() | |
class UI: | |
def __init__(self): | |
self.service = Service() | |
def render(self): | |
print(self.service.process()) | |
if __name__ == '__main__': | |
ui = UI() | |
ui.render() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment