Check this tutorial: https://towardsdatascience.com/build-an-async-python-service-with-fastapi-sqlalchemy-196d8792fa08
at the end there is a section just before conclusion,
from fastapi import Depends
.
.
@router.post("/books")
async def create_book(..., book_dal: BookDAL = Depends(get_book_dal)):
return await book_dal.create_book(...)
This Depeneds
, how can i do this Sanic.
I know it is posssible from,
https://sanic.dev/en/plugins/sanic-ext/injection.html
https://sanic.dev/en/guide/how-to/orm.html#sqlalchemy
But i just can’t connect the dots.
async def foo(*_):
print('ENTER !!!!!!!!!!!')
yield 'bar'
print('EXIT !!!!!!!!!!!!')
app.ext.dependency(foo)
I have no idea what’s happening.
Please if possible, provide an real world example like that tutorial with, “injection+sqlalchemy+context(app+request)”
Please!