Skip to content

Instantly share code, notes, and snippets.

@lastlegion
Created August 31, 2020 23:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lastlegion/43d46d4e148dcfef02ea081887736401 to your computer and use it in GitHub Desktop.
Save lastlegion/43d46d4e148dcfef02ea081887736401 to your computer and use it in GitHub Desktop.
Dependency injection example 1
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