import os from dependency_injector import containers, providers from api.repository.user import UserRepository from api.service.user import UserService from api.uow.database import Database from api.uow.uow_base import UowBase class Container(containers.DeclarativeContainer): wiring_config = containers.WiringConfiguration(modules=["api.router.user"]) config = providers.Configuration(yaml_files=[f"{os.getenv('CONFIG_PATH')}"]) if os.getenv("INDOCKER"): config.db.host.update("db") db = providers.Singleton( Database, db_url="postgresql+asyncpg://{}:{}@{}:{}/{}".format( config.db.user, config.db.password, config.db.host, # config.db.port, "5432", config.db.database, ), ) uow = providers.Factory( UowBase, session_factory=db.provided.session, ) user_repository = providers.Factory( UserRepository, uow=uow, ) user_service = providers.Factory( UserService, user_repository=user_repository, )