service_man/api/app_builder/main.py

25 lines
471 B
Python
Raw Normal View History

2024-03-31 21:07:59 +03:00
from collections.abc import AsyncGenerator
from contextlib import asynccontextmanager
2024-03-31 00:58:43 +03:00
from fastapi import FastAPI
2024-03-31 04:18:41 +03:00
from api.app_builder.dependencies import init_dependencies
2024-03-31 00:58:43 +03:00
from .routers import init_routers
2024-03-31 21:07:59 +03:00
@asynccontextmanager
async def lifespan(app: FastAPI) -> AsyncGenerator:
print("init lifespan")
yield
2024-03-31 00:58:43 +03:00
def app_factory() -> FastAPI:
2024-03-31 21:07:59 +03:00
app = FastAPI(
lifespan=lifespan,
)
2024-03-31 04:18:41 +03:00
init_dependencies(app)
2024-03-31 00:58:43 +03:00
init_routers(app)
2024-03-31 04:18:41 +03:00
2024-03-31 00:58:43 +03:00
return app