mirror of
https://github.com/ets-labs/python-dependency-injector.git
synced 2024-11-30 05:23:59 +03:00
7d160cb4a5
* Update main example * Updating wiring module * Update wiring test case name * Implement string imports for wiring * Update example * Refactor implementation * Update front example * Fix a typo in README * Update wiring docs * Update single container example * Update multiple containers example * Update quotes in multiple containers example * Update quotes in single container example * Update decoupled-packages example * Update single and multiple containers example * Update quotes * Update fastapi+redis example * Update resource docs * Update quotes in CLI tutorial * Update CLI application (movie lister) tutorial * Update monitoring daemon example * Update python version in asyncio daemon example * Update asyncio daemon tutorial * Update quotes in wiring docs * Update wiring docs
53 lines
1.1 KiB
Python
53 lines
1.1 KiB
Python
"""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()
|
|
|
|
logging = providers.Resource(
|
|
logging.config.fileConfig,
|
|
fname="logging.ini",
|
|
)
|
|
|
|
# Gateways
|
|
|
|
database_client = providers.Singleton(
|
|
sqlite3.connect,
|
|
config.database.dsn,
|
|
)
|
|
|
|
s3_client = providers.Singleton(
|
|
boto3.client,
|
|
service_name="s3",
|
|
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,
|
|
)
|