diff --git a/README.rst b/README.rst index dd181897..fc05bb3f 100644 --- a/README.rst +++ b/README.rst @@ -52,30 +52,31 @@ Installation pip install dependency_injector -Examples --------- +Example +------- .. code-block:: python - """Dependency Injector initial example.""" + """Dependency Injector example.""" import sys import sqlite3 - import boto.s3.connection - import services + from boto.s3.connection import S3Connection from dependency_injector import catalogs from dependency_injector import providers from dependency_injector import injections + import services # Example business services module (Users, Photos, Auth) + class Platform(catalogs.DeclarativeCatalog): """Catalog of platform service providers.""" database = providers.Singleton(sqlite3.connect, ':memory:') - s3 = providers.Singleton(boto.s3.connection.S3Connection, + s3 = providers.Singleton(S3Connection, aws_access_key_id='KEY', aws_secret_access_key='SECRET') @@ -97,19 +98,13 @@ Examples @injections.inject(users_service=Services.users) @injections.inject(auth_service=Services.auth) - def main(argv, users_service, auth_service): + @injections.inject(photos_service=Services.photos) + def main(argv, users_service, auth_service, photos_service): """Main function.""" login, password, photo_path = argv[1:] user = users_service.get_user(login) auth_service.authenticate(user, password) - - upload_photo(user, photo_path) - - - @injections.inject(photos_service=Services.photos) - def upload_photo(user, photo_path, photos_service): - """Upload photo.""" photos_service.upload_photo(user['id'], photo_path) diff --git a/examples/initial.py b/examples/example.py similarity index 81% rename from examples/initial.py rename to examples/example.py index 1bca84dc..c107e676 100644 --- a/examples/initial.py +++ b/examples/example.py @@ -1,22 +1,23 @@ -"""Dependency Injector initial example.""" +"""Dependency Injector example.""" import sys import sqlite3 -import boto.s3.connection -import services +from boto.s3.connection import S3Connection from dependency_injector import catalogs from dependency_injector import providers from dependency_injector import injections +import services # Example business services module (Users, Photos, Auth) + class Platform(catalogs.DeclarativeCatalog): """Catalog of platform service providers.""" database = providers.Singleton(sqlite3.connect, ':memory:') - s3 = providers.Singleton(boto.s3.connection.S3Connection, + s3 = providers.Singleton(S3Connection, aws_access_key_id='KEY', aws_secret_access_key='SECRET') @@ -38,19 +39,13 @@ class Services(catalogs.DeclarativeCatalog): @injections.inject(users_service=Services.users) @injections.inject(auth_service=Services.auth) -def main(argv, users_service, auth_service): +@injections.inject(photos_service=Services.photos) +def main(argv, users_service, auth_service, photos_service): """Main function.""" login, password, photo_path = argv[1:] user = users_service.get_user(login) auth_service.authenticate(user, password) - - upload_photo(user, photo_path) - - -@injections.inject(photos_service=Services.photos) -def upload_photo(user, photo_path, photos_service): - """Upload photo.""" photos_service.upload_photo(user['id'], photo_path)