mirror of
https://github.com/ets-labs/python-dependency-injector.git
synced 2025-01-30 19:24:31 +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
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
|
||||
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.
|
||||
|
||||
|
|
|
@ -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()
|
||||
|
|
Loading…
Reference in New Issue
Block a user