Created
September 1, 2020 00:03
-
-
Save lastlegion/a80fdf6f6e388d64ad612d1a243e2c00 to your computer and use it in GitHub Desktop.
This file contains 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
import pinject | |
import os | |
class Repository: | |
def __init__(self, db: str): | |
self.db = db | |
def get_data(self): | |
return 'Hello World' | |
class RepositoryBindingSpec(pinject.BindingSpec): | |
def provide_repository(self): | |
return Repository(db=os.getenv('dbname')) | |
class Service: | |
def __init__(self, repository: Repository): | |
self.repository = repository | |
def process(self): | |
return self.repository.get_data() | |
class UI: | |
def __init__(self, service: Service): | |
self.service = service | |
def render(self): | |
print(self.service.process()) | |
if __name__ == '__main__': | |
object_graph = pinject.new_object_graph(binding_specs=[RepositoryBindingSpec()]) | |
ui = object_graph.provide(UI) | |
ui.render() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment