Created
February 20, 2019 01:37
-
-
Save CreatCodeBuild/11e80e20be0e9aee85e644aa2ff09cd5 to your computer and use it in GitHub Desktop.
Dependency Injection: A Python Flask Example
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
from flask import Flask | |
class DAO: | |
def __init__(self): | |
self.data = [] | |
def App(dao): | |
app = Flask("example") | |
@app.route("/") | |
def m(): | |
return dao.data | |
return app | |
if __name__ == "__main__": | |
app = App(DAO()) | |
app.run() |
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
from flask import Flask | |
app = Flask("example") | |
class DAO: | |
def __init__(self): | |
self.data = [] | |
dao = DAO() | |
@app.route("/") | |
def m(): | |
return dao.data | |
if __name__ == "__main__": | |
app.run() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment