2015-11-21 21:59:36 +00:00
|
|
|
"""`Factory` providers example."""
|
2015-06-05 08:29:36 +00:00
|
|
|
|
2016-06-08 13:39:53 +00:00
|
|
|
import collections
|
2016-06-08 13:54:47 +00:00
|
|
|
|
2016-06-06 08:54:05 +00:00
|
|
|
import dependency_injector.providers as providers
|
2015-06-05 08:29:36 +00:00
|
|
|
|
|
|
|
|
2016-06-08 13:39:53 +00:00
|
|
|
User = collections.namedtuple('User', [])
|
2015-06-05 08:29:36 +00:00
|
|
|
|
|
|
|
# Factory provider creates new instance of specified class on every call.
|
2015-11-21 21:59:36 +00:00
|
|
|
users_factory = providers.Factory(User)
|
2015-06-05 08:29:36 +00:00
|
|
|
|
2015-06-10 09:00:43 +00:00
|
|
|
# Creating several User objects:
|
2016-06-08 13:39:53 +00:00
|
|
|
user1 = users_factory() # Same as: user1 = User()
|
|
|
|
user2 = users_factory() # Same as: user2 = User()
|