2015-09-02 22:18:13 +03:00
|
|
|
"""`di.Factory` providers example."""
|
2015-06-05 11:29:36 +03:00
|
|
|
|
2015-09-02 22:18:13 +03:00
|
|
|
import dependency_injector as di
|
2015-06-05 11:29:36 +03:00
|
|
|
|
|
|
|
|
|
|
|
class User(object):
|
|
|
|
"""Example class User."""
|
|
|
|
|
|
|
|
# Factory provider creates new instance of specified class on every call.
|
2015-09-02 22:18:13 +03:00
|
|
|
users_factory = di.Factory(User)
|
2015-06-05 11:29:36 +03:00
|
|
|
|
2015-06-10 12:00:43 +03:00
|
|
|
# Creating several User objects:
|
2015-06-05 11:29:36 +03:00
|
|
|
user1 = users_factory()
|
|
|
|
user2 = users_factory()
|
|
|
|
|
2015-06-10 12:00:43 +03:00
|
|
|
# Making some asserts:
|
2015-06-05 11:29:36 +03:00
|
|
|
assert user1 is not user2
|
|
|
|
assert isinstance(user1, User) and isinstance(user2, User)
|