2015-11-23 15:43:11 +03:00
|
|
|
"""`Singleton` providers resetting example."""
|
2015-06-10 12:00:43 +03:00
|
|
|
|
2016-06-08 17:46:40 +03:00
|
|
|
import collections
|
|
|
|
|
2016-06-06 11:54:05 +03:00
|
|
|
import dependency_injector.providers as providers
|
2015-06-10 12:00:43 +03:00
|
|
|
|
|
|
|
|
2016-06-08 17:46:40 +03:00
|
|
|
UsersService = collections.namedtuple('UsersService', [])
|
2015-06-10 12:00:43 +03:00
|
|
|
|
2015-06-18 14:45:26 +03:00
|
|
|
# Users service singleton provider:
|
2016-06-08 17:46:40 +03:00
|
|
|
users_service_provider = providers.Singleton(UsersService)
|
2015-06-10 12:00:43 +03:00
|
|
|
|
2016-06-08 17:46:40 +03:00
|
|
|
# Retrieving several UsersService objects:
|
|
|
|
users_service1 = users_service_provider()
|
|
|
|
users_service2 = users_service_provider()
|
2015-06-10 12:00:43 +03:00
|
|
|
|
|
|
|
# Making some asserts:
|
2016-06-08 17:46:40 +03:00
|
|
|
assert users_service1 is users_service2
|
2015-06-10 12:00:43 +03:00
|
|
|
|
|
|
|
# Resetting of memorized instance:
|
|
|
|
users_service_provider.reset()
|
|
|
|
|
|
|
|
# Retrieving one more UserService object:
|
2016-06-08 17:46:40 +03:00
|
|
|
users_service3 = users_service_provider()
|
2015-06-10 12:00:43 +03:00
|
|
|
|
|
|
|
# Making some asserts:
|
2016-06-08 17:46:40 +03:00
|
|
|
assert users_service3 is not users_service1
|