1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23
|
from typing import TYPE_CHECKING
from litestar import Litestar
if TYPE_CHECKING:
from litestar.config.app import AppConfig
async def close_db_connection() -> None:
"""Closes the database connection on application shutdown."""
def receive_app_config(app_config: "AppConfig") -> "AppConfig":
"""Receives parameters from the application.
In reality, this would be a library of boilerplate that is carried from one application to another, or a third-party
developed application configuration tool.
"""
app_config.on_shutdown.append(close_db_connection)
return app_config
app = Litestar([], on_app_init=[receive_app_config])
|