python-dependency-injector/examples/providers/factory.py

16 lines
401 B
Python
Raw Normal View History

"""`Factory` providers example."""
2016-06-08 13:39:53 +00:00
import collections
2016-06-06 08:54:05 +00:00
import dependency_injector.providers as providers
2016-06-08 13:39:53 +00:00
User = collections.namedtuple('User', [])
# Factory provider creates new instance of specified class on every call.
users_factory = providers.Factory(User)
# 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()