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