config di lifespan
This commit is contained in:
@@ -10,11 +10,14 @@ from api.infrastructure.dependencies.adapters import (
|
||||
new_session,
|
||||
new_unit_of_work,
|
||||
)
|
||||
from api.infrastructure.dependencies.configs import app_settings
|
||||
from api.infrastructure.dependencies.repositories import get_user_repository
|
||||
from api.infrastructure.dependencies.usecases import provide_create_user
|
||||
from api.infrastructure.settings import Settings
|
||||
|
||||
|
||||
def init_dependencies(app: FastAPI) -> None:
|
||||
app.dependency_overrides[Settings] = app_settings
|
||||
app.dependency_overrides[AsyncEngine] = create_engine
|
||||
app.dependency_overrides[async_sessionmaker[AsyncSession]] = create_session_maker
|
||||
app.dependency_overrides[AsyncSession] = new_session
|
||||
|
@@ -1,3 +1,6 @@
|
||||
from collections.abc import AsyncGenerator
|
||||
from contextlib import asynccontextmanager
|
||||
|
||||
from fastapi import FastAPI
|
||||
|
||||
from api.app_builder.dependencies import init_dependencies
|
||||
@@ -5,8 +8,16 @@ from api.app_builder.dependencies import init_dependencies
|
||||
from .routers import init_routers
|
||||
|
||||
|
||||
@asynccontextmanager
|
||||
async def lifespan(app: FastAPI) -> AsyncGenerator:
|
||||
print("init lifespan")
|
||||
yield
|
||||
|
||||
|
||||
def app_factory() -> FastAPI:
|
||||
app = FastAPI()
|
||||
app = FastAPI(
|
||||
lifespan=lifespan,
|
||||
)
|
||||
init_dependencies(app)
|
||||
init_routers(app)
|
||||
|
||||
|
Reference in New Issue
Block a user