Skip to content

Commit

Permalink
Update services miniapp example
Browse files Browse the repository at this point in the history
  • Loading branch information
rmk135 committed Mar 15, 2017
1 parent a677755 commit ca9c135
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 25 deletions.
24 changes: 12 additions & 12 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -292,20 +292,20 @@ 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')
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):
Expand All @@ -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,
Expand Down Expand Up @@ -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:
Expand Down
16 changes: 8 additions & 8 deletions examples/miniapps/services/containers.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import logging
import sqlite3

import boto.s3.connection
import boto3

import example.main
import example.services
Expand All @@ -15,20 +15,20 @@
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')


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):
Expand All @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion examples/miniapps/services/example/services.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ def __init__(self, logger, db, s3):
: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
Expand Down
8 changes: 4 additions & 4 deletions examples/miniapps/services/run.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@

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:
Expand Down

0 comments on commit ca9c135

Please sign in to comment.