that-depends
that-depends copied to clipboard
Shared, and exported `create_container_lifespan` for frameworks
It would be a (small) DX boost not to have to write lifespan yourself. Applicable for FastAPI, Litestar and FastStream.
def create_container_lifespan(*containers: that_depends.BaseContainer):
@contextlib.asynccontextmanager
async def lifespan(*_args: typing.Any, **kwargs: typing.Any) -> typing.AsyncIterator[None]:
try:
yield
finally:
for one_container in containers:
await one_container.DIContainer.tear_down()
return lifespan
Maybe it can be useful