service_man/api/di.py

30 lines
612 B
Python
Raw Normal View History

2024-03-11 21:07:01 +03:00
from sqlalchemy.ext.asyncio import (AsyncSession, async_sessionmaker,
create_async_engine)
2024-03-04 13:15:28 +03:00
2024-03-11 07:48:04 +03:00
from api.config import get_settings
2024-03-11 21:07:01 +03:00
from api.services.user import UserService
2024-03-06 02:28:59 +03:00
from api.uow.uow_base import UnitOfWork
2024-03-04 07:12:29 +03:00
2024-03-11 07:48:04 +03:00
async_engine = create_async_engine(
url=get_settings().get_db_url,
2024-03-11 21:07:01 +03:00
echo=False,
2024-03-11 07:48:04 +03:00
)
2024-03-04 07:12:29 +03:00
2024-03-11 07:48:04 +03:00
async_session_factory = async_sessionmaker(
async_engine,
class_=AsyncSession,
expire_on_commit=False,
)
2024-03-04 07:12:29 +03:00
2024-03-11 07:48:04 +03:00
uow = UnitOfWork(
session_factory=async_session_factory,
)
2024-03-06 02:28:59 +03:00
2024-03-11 07:48:04 +03:00
user_service = UserService(
uow=uow,
)
2024-03-04 07:12:29 +03:00
2024-03-04 13:15:28 +03:00
2024-03-11 07:48:04 +03:00
def get_user_service():
return user_service