2016-05-22 16:02:10 +03:00
|
|
|
"""Example of several Dependency Injector IoC containers."""
|
2016-05-18 23:18:29 +03:00
|
|
|
|
|
|
|
import sqlite3
|
|
|
|
import boto.s3.connection
|
|
|
|
import example.services
|
|
|
|
|
2016-05-27 14:38:42 +03:00
|
|
|
from dependency_injector import containers
|
2016-05-18 23:18:29 +03:00
|
|
|
from dependency_injector import providers
|
|
|
|
|
|
|
|
|
2016-05-27 14:38:42 +03:00
|
|
|
class Platform(containers.DeclarativeContainer):
|
|
|
|
"""Container of platform service providers."""
|
2016-05-18 23:18:29 +03:00
|
|
|
|
|
|
|
database = providers.Singleton(sqlite3.connect, ':memory:')
|
|
|
|
|
|
|
|
s3 = providers.Singleton(boto.s3.connection.S3Connection,
|
|
|
|
aws_access_key_id='KEY',
|
|
|
|
aws_secret_access_key='SECRET')
|
|
|
|
|
|
|
|
|
2016-05-27 14:38:42 +03:00
|
|
|
class Services(containers.DeclarativeContainer):
|
|
|
|
"""Container of business service providers."""
|
2016-05-18 23:18:29 +03:00
|
|
|
|
|
|
|
users = providers.Factory(example.services.Users,
|
|
|
|
db=Platform.database)
|
|
|
|
|
|
|
|
photos = providers.Factory(example.services.Photos,
|
|
|
|
db=Platform.database,
|
|
|
|
s3=Platform.s3)
|
|
|
|
|
|
|
|
auth = providers.Factory(example.services.Auth,
|
|
|
|
db=Platform.database,
|
|
|
|
token_ttl=3600)
|