2015-11-23 12:43:11 +00:00
|
|
|
"""`Singleton` providers resetting example."""
|
2015-06-10 09:00:43 +00:00
|
|
|
|
2015-11-23 12:43:11 +00:00
|
|
|
from dependency_injector import providers
|
2015-06-10 09:00:43 +00:00
|
|
|
|
|
|
|
|
|
|
|
class UserService(object):
|
|
|
|
"""Example class UserService."""
|
|
|
|
|
2015-06-18 11:45:26 +00:00
|
|
|
# Users service singleton provider:
|
2015-11-23 12:43:11 +00:00
|
|
|
users_service_provider = providers.Singleton(UserService)
|
2015-06-10 09:00:43 +00:00
|
|
|
|
|
|
|
# Retrieving several UserService objects:
|
|
|
|
user_service1 = users_service_provider()
|
|
|
|
user_service2 = users_service_provider()
|
|
|
|
|
|
|
|
# Making some asserts:
|
|
|
|
assert user_service1 is user_service2
|
|
|
|
assert isinstance(user_service1, UserService)
|
|
|
|
assert isinstance(user_service2, UserService)
|
|
|
|
|
|
|
|
# Resetting of memorized instance:
|
|
|
|
users_service_provider.reset()
|
|
|
|
|
|
|
|
# Retrieving one more UserService object:
|
|
|
|
user_service3 = users_service_provider()
|
|
|
|
|
|
|
|
# Making some asserts:
|
|
|
|
assert user_service3 is not user_service1
|