2020-09-07 04:51:38 +03:00
|
|
|
"""Containers module."""
|
|
|
|
|
|
|
|
import sqlite3
|
|
|
|
|
|
|
|
import boto3
|
|
|
|
from dependency_injector import containers, providers
|
|
|
|
|
|
|
|
from .user.containers import UserContainer
|
|
|
|
from .photo.containers import PhotoContainer
|
|
|
|
from .analytics.containers import AnalyticsContainer
|
|
|
|
|
|
|
|
|
|
|
|
class ApplicationContainer(containers.DeclarativeContainer):
|
|
|
|
|
2021-10-28 00:06:24 +03:00
|
|
|
config = providers.Configuration(ini_files=["config.ini"])
|
2020-09-07 04:51:38 +03:00
|
|
|
|
|
|
|
sqlite = providers.Singleton(sqlite3.connect, config.database.dsn)
|
|
|
|
|
|
|
|
s3 = providers.Singleton(
|
|
|
|
boto3.client,
|
2021-09-30 22:03:19 +03:00
|
|
|
service_name="s3",
|
2020-09-07 04:51:38 +03:00
|
|
|
aws_access_key_id=config.aws.access_key_id,
|
|
|
|
aws_secret_access_key=config.aws.secret_access_key,
|
|
|
|
)
|
|
|
|
|
|
|
|
user_package = providers.Container(
|
|
|
|
UserContainer,
|
|
|
|
database=sqlite,
|
|
|
|
)
|
|
|
|
|
|
|
|
photo_package = providers.Container(
|
|
|
|
PhotoContainer,
|
|
|
|
database=sqlite,
|
|
|
|
file_storage=s3,
|
|
|
|
)
|
|
|
|
|
|
|
|
analytics_package = providers.Container(
|
|
|
|
AnalyticsContainer,
|
|
|
|
user_repository=user_package.user_repository,
|
|
|
|
photo_repository=photo_package.photo_repository,
|
|
|
|
)
|