service_man/api/di.py

35 lines
910 B
Python

import os
from dependency_injector import containers, providers
from repository.user import UserRepository
from service.user import UserService
from uow.database import Database
class Container(containers.DeclarativeContainer):
wiring_config = containers.WiringConfiguration(modules=["router.user"])
config = providers.Configuration(yaml_files=[f"{os.getenv('CONFIG_PATH')}"])
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,
),
)
user_repository = providers.Factory(
UserRepository,
session_factory=db.provided.session,
)
user_service = providers.Factory(
UserService,
user_repository=user_repository,
)