2020-09-05 06:19:32 +03:00
|
|
|
"""Containers module."""
|
|
|
|
|
|
|
|
import logging.config
|
|
|
|
import sqlite3
|
|
|
|
|
|
|
|
import boto3
|
|
|
|
from dependency_injector import containers, providers
|
|
|
|
|
|
|
|
from . import services
|
|
|
|
|
|
|
|
|
|
|
|
class Container(containers.DeclarativeContainer):
|
|
|
|
|
|
|
|
config = providers.Configuration()
|
|
|
|
|
2020-10-29 05:20:49 +03:00
|
|
|
logging = providers.Resource(
|
2020-09-05 06:19:32 +03:00
|
|
|
logging.config.fileConfig,
|
2021-09-30 22:03:19 +03:00
|
|
|
fname="logging.ini",
|
2020-09-05 06:19:32 +03:00
|
|
|
)
|
|
|
|
|
|
|
|
# Gateways
|
|
|
|
|
|
|
|
database_client = providers.Singleton(
|
|
|
|
sqlite3.connect,
|
|
|
|
config.database.dsn,
|
|
|
|
)
|
|
|
|
|
|
|
|
s3_client = providers.Singleton(
|
|
|
|
boto3.client,
|
2021-09-30 22:03:19 +03:00
|
|
|
service_name="s3",
|
2020-09-05 06:19:32 +03:00
|
|
|
aws_access_key_id=config.aws.access_key_id,
|
|
|
|
aws_secret_access_key=config.aws.secret_access_key,
|
|
|
|
)
|
|
|
|
|
|
|
|
# Services
|
|
|
|
|
|
|
|
user_service = providers.Factory(
|
|
|
|
services.UserService,
|
|
|
|
db=database_client,
|
|
|
|
)
|
|
|
|
|
|
|
|
auth_service = providers.Factory(
|
|
|
|
services.AuthService,
|
|
|
|
db=database_client,
|
|
|
|
token_ttl=config.auth.token_ttl.as_int(),
|
|
|
|
)
|
|
|
|
|
|
|
|
photo_service = providers.Factory(
|
|
|
|
services.PhotoService,
|
|
|
|
db=database_client,
|
|
|
|
s3=s3_client,
|
|
|
|
)
|