mirror of
https://github.com/ets-labs/python-dependency-injector.git
synced 2025-01-31 11:51:39 +03:00
Update factory attribute injections docs
This commit is contained in:
parent
479f50fb76
commit
2d5ce49254
Binary file not shown.
Before Width: | Height: | Size: 32 KiB After Width: | Height: | Size: 29 KiB |
|
@ -72,7 +72,7 @@ So, please, follow the example below:
|
||||||
Factory providers and attribute injections
|
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
|
attribute injections. Those injections are done by setting specified attributes
|
||||||
with injectable values right after object's creation.
|
with injectable values right after object's creation.
|
||||||
|
|
||||||
|
|
|
@ -1,7 +1,6 @@
|
||||||
"""`Factory` providers with attribute injections example."""
|
"""`di.Factory` providers with attribute injections example."""
|
||||||
|
|
||||||
from dependency_injector.providers import Factory
|
import dependency_injector as di
|
||||||
from dependency_injector.injections import Attribute
|
|
||||||
|
|
||||||
|
|
||||||
class User(object):
|
class User(object):
|
||||||
|
@ -24,11 +23,11 @@ class CreditCard(object):
|
||||||
"""Example class CreditCard."""
|
"""Example class CreditCard."""
|
||||||
|
|
||||||
# User, Photo and CreditCard factories:
|
# User, Photo and CreditCard factories:
|
||||||
credit_cards_factory = Factory(CreditCard)
|
credit_cards_factory = di.Factory(CreditCard)
|
||||||
photos_factory = Factory(Photo)
|
photos_factory = di.Factory(Photo)
|
||||||
users_factory = Factory(User,
|
users_factory = di.Factory(User,
|
||||||
Attribute('main_photo', photos_factory),
|
di.Attribute('main_photo', photos_factory),
|
||||||
Attribute('credit_card', credit_cards_factory))
|
di.Attribute('credit_card', credit_cards_factory))
|
||||||
|
|
||||||
# Creating several User objects:
|
# Creating several User objects:
|
||||||
user1 = users_factory()
|
user1 = users_factory()
|
||||||
|
|
Loading…
Reference in New Issue
Block a user