2021-02-05 02:18:25 +03:00
|
|
|
"""Containers module."""
|
|
|
|
|
|
|
|
from dependency_injector import containers, providers
|
|
|
|
|
|
|
|
from .database import Database
|
|
|
|
from .repositories import UserRepository
|
|
|
|
from .services import UserService
|
|
|
|
|
|
|
|
|
|
|
|
class Container(containers.DeclarativeContainer):
|
|
|
|
|
2021-11-01 03:31:39 +03:00
|
|
|
wiring_config = containers.WiringConfiguration(modules=[".endpoints"])
|
|
|
|
|
|
|
|
config = providers.Configuration(yaml_files=["config.yml"])
|
2021-02-05 02:18:25 +03:00
|
|
|
|
|
|
|
db = providers.Singleton(Database, db_url=config.db.url)
|
|
|
|
|
|
|
|
user_repository = providers.Factory(
|
|
|
|
UserRepository,
|
|
|
|
session_factory=db.provided.session,
|
|
|
|
)
|
|
|
|
|
|
|
|
user_service = providers.Factory(
|
|
|
|
UserService,
|
|
|
|
user_repository=user_repository,
|
|
|
|
)
|