python-dependency-injector
python-dependency-injector copied to clipboard
AutoWiring entire module not works on AioHTTP decorated routes
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