How to import ext.injection?

class FakeConnection:
    async def execute(self, query: str, **arguments):
        return "result"


@app.before_server_start
async def setup_db(app, _):
    app.ctx.db_conn = FakeConnection()


def get_db(request: Request):
    return request.app.ctx.db_conn


ext.injection(FakeConnection, get_db)   # how to import ext.injection


@app.get("/")
async def handler(request, conn: FakeConnection):
    response = await conn.execute("...")
    return text(response)

I could not find the correct injection location using PyCharm’s auto_import

It is not imported. ext is a property of your Sanic instance.

app.ext.injection
1 Like

I find that the document of ext.injection page is different from that of other languages

If I want to modify the Chinese document, where do I need to go to get the demand?

url:
https://sanic.dev/zh/plugins/sanic-ext/injection.html

On the bottom of the page is a link to the source that generates the page.