Update Factory method injections docs

This commit is contained in:
Roman Mogilatov 2015-09-02 22:59:06 +03:00
parent b8a30601df
commit 479f50fb76
3 changed files with 9 additions and 10 deletions

Binary file not shown.

Before

Width:  |  Height:  |  Size: 34 KiB

After

Width:  |  Height:  |  Size: 31 KiB

View File

@ -86,13 +86,13 @@ Example:
Factory providers and method injections
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Current example shows how to create ``Factory`` of particular class with
Current example shows how to create ``di.Factory`` of particular class with
method injections. Those injections are done by calling of specified method
with injectable value right after object's creation and attribute injections
are done.
Method injections are not very popular in Python due Python best practices
(usage of public attributes instead of setter methods), but it may appear in
(usage of public attributes instead of setter methods), but they may appear in
some cases.
Example:

View File

@ -1,7 +1,6 @@
"""`Factory` providers with method injections example."""
"""`di.Factory` providers with method injections example."""
from dependency_injector.providers import Factory
from dependency_injector.injections import Method
import dependency_injector as di
class User(object):
@ -32,11 +31,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,
Method('set_main_photo', photos_factory),
Method('set_credit_card', credit_cards_factory))
credit_cards_factory = di.Factory(CreditCard)
photos_factory = di.Factory(Photo)
users_factory = di.Factory(User,
di.Method('set_main_photo', photos_factory),
di.Method('set_credit_card', credit_cards_factory))
# Creating several User objects:
user1 = users_factory()