Update miniapps

This commit is contained in:
Roman Mogilatov 2016-06-01 19:52:10 +03:00
parent 5ecb00daba
commit 209bc518c3
5 changed files with 42 additions and 44 deletions

View File

@ -64,8 +64,8 @@ system that consists from several business and platform services:
import boto.s3.connection
import example.services
from dependency_injector import containers
from dependency_injector import providers
import dependency_injector.containers as containers
import dependency_injector.providers as providers
class Platform(containers.DeclarativeContainer):
@ -84,14 +84,14 @@ system that consists from several business and platform services:
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)
photos = providers.Factory(example.services.Photos,
db=Platform.database,
s3=Platform.s3)
Next example demonstrates usage of ``@inject`` decorator with IoC containers
defined above:
@ -99,14 +99,13 @@ defined above:
"""Dependency Injector @inject decorator example."""
from dependency_injector.injections import inject
from containers import Services
import dependency_injector.injections as di
import containers
@inject(users_service=Services.users)
@inject(auth_service=Services.auth)
@inject(photos_service=Services.photos)
@di.inject(users_service=containers.Services.users)
@di.inject(auth_service=containers.Services.auth)
@di.inject(photos_service=containers.Services.photos)
def main(users_service, auth_service, photos_service):
"""Main function."""
user = users_service.get_user('user')
@ -144,14 +143,14 @@ IoC containers from previous example could look like these:
users = providers.Factory(example.services.Users) \
.add_kwargs(db=Platform.database)
photos = providers.Factory(example.services.Photos) \
.add_kwargs(db=Platform.database,
s3=Platform.s3)
auth = providers.Factory(example.services.Auth) \
.add_kwargs(db=Platform.database,
token_ttl=3600)
photos = providers.Factory(example.services.Photos) \
.add_kwargs(db=Platform.database,
s3=Platform.s3)
or like this these:
.. code-block:: python
@ -173,14 +172,14 @@ or like this these:
users = providers.Factory(example.services.Users)
users.add_kwargs(db=Platform.database)
photos = providers.Factory(example.services.Photos)
photos.add_kwargs(db=Platform.database,
s3=Platform.s3)
auth = providers.Factory(example.services.Auth)
auth.add_kwargs(db=Platform.database,
token_ttl=3600)
photos = providers.Factory(example.services.Photos)
photos.add_kwargs(db=Platform.database,
s3=Platform.s3)
You can get more *Dependency Injector* examples in ``/examples`` directory on
GitHub:

View File

@ -4,8 +4,8 @@ import sqlite3
import boto.s3.connection
import example.services
from dependency_injector import containers
from dependency_injector import providers
import dependency_injector.containers as containers
import dependency_injector.providers as providers
class Platform(containers.DeclarativeContainer):
@ -24,10 +24,10 @@ class Services(containers.DeclarativeContainer):
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)
photos = providers.Factory(example.services.Photos,
db=Platform.database,
s3=Platform.s3)

View File

@ -7,8 +7,8 @@ import sqlite3
import boto.s3.connection
import example.services
from dependency_injector import containers
from dependency_injector import providers
import dependency_injector.containers as containers
import dependency_injector.providers as providers
class Platform(containers.DeclarativeContainer):
@ -28,10 +28,10 @@ class Services(containers.DeclarativeContainer):
users = providers.Factory(example.services.Users) \
.add_kwargs(db=Platform.database)
photos = providers.Factory(example.services.Photos) \
.add_kwargs(db=Platform.database,
s3=Platform.s3)
auth = providers.Factory(example.services.Auth) \
.add_kwargs(db=Platform.database,
token_ttl=3600)
photos = providers.Factory(example.services.Photos) \
.add_kwargs(db=Platform.database,
s3=Platform.s3)

View File

@ -7,8 +7,8 @@ import sqlite3
import boto.s3.connection
import example.services
from dependency_injector import containers
from dependency_injector import providers
import dependency_injector.containers as containers
import dependency_injector.providers as providers
class Platform(containers.DeclarativeContainer):
@ -28,10 +28,10 @@ class Services(containers.DeclarativeContainer):
users = providers.Factory(example.services.Users)
users.add_kwargs(db=Platform.database)
photos = providers.Factory(example.services.Photos)
photos.add_kwargs(db=Platform.database,
s3=Platform.s3)
auth = providers.Factory(example.services.Auth)
auth.add_kwargs(db=Platform.database,
token_ttl=3600)
photos = providers.Factory(example.services.Photos)
photos.add_kwargs(db=Platform.database,
s3=Platform.s3)

View File

@ -1,13 +1,12 @@
"""Dependency Injector @inject decorator example."""
from dependency_injector.injections import inject
from containers import Services
import dependency_injector.injections as di
import containers
@inject(users_service=Services.users)
@inject(auth_service=Services.auth)
@inject(photos_service=Services.photos)
@di.inject(users_service=containers.Services.users)
@di.inject(auth_service=containers.Services.auth)
@di.inject(photos_service=containers.Services.photos)
def main(users_service, auth_service, photos_service):
"""Main function."""
user = users_service.get_user('user')