service_man/api/app_entrypoint/dependencies.py

68 lines
2.7 KiB
Python

from fastapi import FastAPI
from sqlalchemy.ext.asyncio import AsyncEngine, AsyncSession, async_sessionmaker
from api.application.abstractions.transaction import TransactionContextManager
from api.application.protocols.date_time import DateTimeProvider
from api.application.protocols.jwt import JwtTokenProcessor
from api.application.protocols.password_hasher import PasswordHasher
from api.application.usecase.auth.auth_user import LoginUser
from api.application.usecase.auth.create_user import CreateUser
from api.application.usecase.company.create_company import CreateCompany
from api.application.usecase.company.get_users_company import GetCompaniesByOwnerEmail
from api.domain.company.repository import CompanyRepository
from api.domain.user.repository import UserRepository
from api.infrastructure.auth.jwt_settings import JwtSettings
from api.infrastructure.dependencies.adapters import (
create_engine,
create_session_maker,
get_transaction_context,
new_session,
)
from api.infrastructure.dependencies.configs import (
app_settings,
get_db_settings,
get_jwt_settings,
)
from api.infrastructure.dependencies.protocols import (
get_date_time_provider,
get_jwt_token_processor,
get_password_hasher,
get_user_login,
)
from api.infrastructure.dependencies.repositories import (
get_company_repository,
get_user_repository,
)
from api.infrastructure.dependencies.usecases import (
provide_create_company,
provide_create_user,
provide_get_companies_by_email,
)
from api.infrastructure.persistence.db_setings import DBSettings
from api.infrastructure.settings import Settings
def init_dependencies(app: FastAPI) -> None:
app.dependency_overrides[DBSettings] = get_db_settings
app.dependency_overrides[JwtSettings] = get_jwt_settings
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
app.dependency_overrides[TransactionContextManager] = get_transaction_context
app.dependency_overrides[DateTimeProvider] = get_date_time_provider
app.dependency_overrides[PasswordHasher] = get_password_hasher
app.dependency_overrides[JwtTokenProcessor] = get_jwt_token_processor
app.dependency_overrides[LoginUser] = get_user_login
app.dependency_overrides[UserRepository] = get_user_repository
app.dependency_overrides[CompanyRepository] = get_company_repository
app.dependency_overrides[CreateUser] = provide_create_user
app.dependency_overrides[GetCompaniesByOwnerEmail] = provide_get_companies_by_email
app.dependency_overrides[CreateCompany] = provide_create_company