mirror of
https://github.com/ets-labs/python-dependency-injector.git
synced 2024-11-22 09:36:48 +03:00
Update services miniapp example
This commit is contained in:
parent
a6777550a9
commit
ca9c13543d
24
README.rst
24
README.rst
|
@ -280,7 +280,7 @@ great opportunity to control & manage application's structure in one place.
|
|||
import logging
|
||||
import sqlite3
|
||||
|
||||
import boto.s3.connection
|
||||
import boto3
|
||||
|
||||
import example.main
|
||||
import example.services
|
||||
|
@ -292,7 +292,7 @@ great opportunity to control & manage application's structure in one place.
|
|||
class Core(containers.DeclarativeContainer):
|
||||
"""IoC container of core component providers."""
|
||||
|
||||
configuration = providers.Configuration('config')
|
||||
config = providers.Configuration('config')
|
||||
|
||||
logger = providers.Singleton(logging.Logger, name='example')
|
||||
|
||||
|
@ -300,12 +300,12 @@ great opportunity to control & manage application's structure in one place.
|
|||
class Gateways(containers.DeclarativeContainer):
|
||||
"""IoC container of gateway (API clients to remote services) providers."""
|
||||
|
||||
database = providers.Singleton(sqlite3.connect,
|
||||
Core.configuration.database.dsn)
|
||||
database = providers.Singleton(sqlite3.connect, Core.config.database.dsn)
|
||||
|
||||
s3 = providers.Singleton(boto.s3.connection.S3Connection,
|
||||
Core.configuration.aws.access_key_id,
|
||||
Core.configuration.aws.secret_access_key)
|
||||
s3 = providers.Singleton(
|
||||
boto3.client, 's3',
|
||||
aws_access_key_id=Core.config.aws.access_key_id,
|
||||
aws_secret_access_key=Core.config.aws.secret_access_key)
|
||||
|
||||
|
||||
class Services(containers.DeclarativeContainer):
|
||||
|
@ -318,7 +318,7 @@ great opportunity to control & manage application's structure in one place.
|
|||
auth = providers.Factory(example.services.AuthService,
|
||||
db=Gateways.database,
|
||||
logger=Core.logger,
|
||||
token_ttl=Core.configuration.auth.token_ttl)
|
||||
token_ttl=Core.config.auth.token_ttl)
|
||||
|
||||
photos = providers.Factory(example.services.PhotosService,
|
||||
db=Gateways.database,
|
||||
|
@ -348,10 +348,10 @@ Next example demonstrates run of example application defined above:
|
|||
|
||||
if __name__ == '__main__':
|
||||
# Configure platform:
|
||||
Core.configuration.update({'database': {'dsn': ':memory:'},
|
||||
'aws': {'access_key_id': 'KEY',
|
||||
'secret_access_key': 'SECRET'},
|
||||
'auth': {'token_ttl': 3600}})
|
||||
Core.config.update({'database': {'dsn': ':memory:'},
|
||||
'aws': {'access_key_id': 'KEY',
|
||||
'secret_access_key': 'SECRET'},
|
||||
'auth': {'token_ttl': 3600}})
|
||||
Core.logger().addHandler(logging.StreamHandler(sys.stdout))
|
||||
|
||||
# Run application:
|
||||
|
|
|
@ -3,7 +3,7 @@
|
|||
import logging
|
||||
import sqlite3
|
||||
|
||||
import boto.s3.connection
|
||||
import boto3
|
||||
|
||||
import example.main
|
||||
import example.services
|
||||
|
@ -15,7 +15,7 @@ import dependency_injector.providers as providers
|
|||
class Core(containers.DeclarativeContainer):
|
||||
"""IoC container of core component providers."""
|
||||
|
||||
configuration = providers.Configuration('config')
|
||||
config = providers.Configuration('config')
|
||||
|
||||
logger = providers.Singleton(logging.Logger, name='example')
|
||||
|
||||
|
@ -23,12 +23,12 @@ class Core(containers.DeclarativeContainer):
|
|||
class Gateways(containers.DeclarativeContainer):
|
||||
"""IoC container of gateway (API clients to remote services) providers."""
|
||||
|
||||
database = providers.Singleton(sqlite3.connect,
|
||||
Core.configuration.database.dsn)
|
||||
database = providers.Singleton(sqlite3.connect, Core.config.database.dsn)
|
||||
|
||||
s3 = providers.Singleton(boto.s3.connection.S3Connection,
|
||||
Core.configuration.aws.access_key_id,
|
||||
Core.configuration.aws.secret_access_key)
|
||||
s3 = providers.Singleton(
|
||||
boto3.client, 's3',
|
||||
aws_access_key_id=Core.config.aws.access_key_id,
|
||||
aws_secret_access_key=Core.config.aws.secret_access_key)
|
||||
|
||||
|
||||
class Services(containers.DeclarativeContainer):
|
||||
|
@ -41,7 +41,7 @@ class Services(containers.DeclarativeContainer):
|
|||
auth = providers.Factory(example.services.AuthService,
|
||||
db=Gateways.database,
|
||||
logger=Core.logger,
|
||||
token_ttl=Core.configuration.auth.token_ttl)
|
||||
token_ttl=Core.config.auth.token_ttl)
|
||||
|
||||
photos = providers.Factory(example.services.PhotosService,
|
||||
db=Gateways.database,
|
||||
|
|
|
@ -82,7 +82,7 @@ class PhotosService(BaseService):
|
|||
:type db: sqlite3.Connection
|
||||
|
||||
:param s3: AWS S3 client.
|
||||
:type s3: boto.s3.connection.S3Connection
|
||||
:type s3: botocore.client.S3
|
||||
"""
|
||||
self.logger = logger
|
||||
self.db = db
|
||||
|
|
|
@ -8,10 +8,10 @@ from containers import Core, Application
|
|||
|
||||
if __name__ == '__main__':
|
||||
# Configure platform:
|
||||
Core.configuration.update({'database': {'dsn': ':memory:'},
|
||||
'aws': {'access_key_id': 'KEY',
|
||||
'secret_access_key': 'SECRET'},
|
||||
'auth': {'token_ttl': 3600}})
|
||||
Core.config.update({'database': {'dsn': ':memory:'},
|
||||
'aws': {'access_key_id': 'KEY',
|
||||
'secret_access_key': 'SECRET'},
|
||||
'auth': {'token_ttl': 3600}})
|
||||
Core.logger().addHandler(logging.StreamHandler(sys.stdout))
|
||||
|
||||
# Run application:
|
||||
|
|
Loading…
Reference in New Issue
Block a user