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

19 lines
444 B
Python
Raw Normal View History

"""`Factory` providers example."""
2016-06-06 11:54:05 +03:00
import dependency_injector.providers as providers
class User(object):
"""Example class User."""
# Factory provider creates new instance of specified class on every call.
users_factory = providers.Factory(User)
# Creating several User objects:
user1 = users_factory()
user2 = users_factory()
# Making some asserts:
assert user1 is not user2
assert isinstance(user1, User) and isinstance(user2, User)