Update factory attribute injections docs

This commit is contained in:
Roman Mogilatov 2015-09-02 23:02:58 +03:00
parent 479f50fb76
commit 2d5ce49254
3 changed files with 8 additions and 9 deletions

Binary file not shown.

Before

Width:  |  Height:  |  Size: 32 KiB

After

Width:  |  Height:  |  Size: 29 KiB

View File

@ -72,7 +72,7 @@ So, please, follow the example below:
Factory providers and attribute injections
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Example below shows how to create ``Factory`` of particular class with
Example below shows how to create ``di.Factory`` of particular class with
attribute injections. Those injections are done by setting specified attributes
with injectable values right after object's creation.

View File

@ -1,7 +1,6 @@
"""`Factory` providers with attribute injections example."""
"""`di.Factory` providers with attribute injections example."""
from dependency_injector.providers import Factory
from dependency_injector.injections import Attribute
import dependency_injector as di
class User(object):
@ -24,11 +23,11 @@ class CreditCard(object):
"""Example class CreditCard."""
# User, Photo and CreditCard factories:
credit_cards_factory = Factory(CreditCard)
photos_factory = Factory(Photo)
users_factory = Factory(User,
Attribute('main_photo', photos_factory),
Attribute('credit_card', credit_cards_factory))
credit_cards_factory = di.Factory(CreditCard)
photos_factory = di.Factory(Photo)
users_factory = di.Factory(User,
di.Attribute('main_photo', photos_factory),
di.Attribute('credit_card', credit_cards_factory))
# Creating several User objects:
user1 = users_factory()