python-dependency-injector icon indicating copy to clipboard operation
python-dependency-injector copied to clipboard

AutoWiring entire module not works on AioHTTP decorated routes

Open dnp1 opened this issue 3 years ago • 0 comments

While this works

@routes.get('/health')
@inject
async def health(_: web.Request, async_session: SessionMaker = Provide[Container.session_maker]) -> web.Response:
    async with async_session() as session:
        query = text('select version(), current_database(), current_user, session_user')
        res = await session.execute(query)
        row = res.fetchone()
    return web.json_response(
        dict(**row)
    )

This does not.

@routes.get('/health')
async def health(_: web.Request, async_session: SessionMaker = Provide[Container.session_maker]) -> web.Response:
    async with async_session() as session:
        query = text('select version(), current_database(), current_user, session_user')
        res = await session.execute(query)
        row = res.fetchone()
    return web.json_response(
        dict(**row)
    )

Even having:

class Container(containers.DeclarativeContainer):
    wiring_config = containers.WiringConfiguration(modules=[".handlers"]) -- health is in handlers
    ...

Without decorated routes it worked

dnp1 avatar Jun 23 '22 03:06 dnp1