2020-09-01 20:04:48 +00:00
|
|
|
"""`Singleton` provider resetting example."""
|
2015-06-10 09:00:43 +00:00
|
|
|
|
2020-09-01 20:04:48 +00:00
|
|
|
from dependency_injector import providers
|
2016-06-08 14:46:40 +00:00
|
|
|
|
2015-06-10 09:00:43 +00:00
|
|
|
|
2020-09-01 20:04:48 +00:00
|
|
|
class UserService:
|
|
|
|
...
|
2015-06-10 09:00:43 +00:00
|
|
|
|
|
|
|
|
2020-09-01 20:04:48 +00:00
|
|
|
user_service_provider = providers.Singleton(UserService)
|
2015-06-10 09:00:43 +00:00
|
|
|
|
|
|
|
|
2020-09-01 20:04:48 +00:00
|
|
|
if __name__ == '__main__':
|
|
|
|
user_service1 = user_service_provider()
|
2015-06-10 09:00:43 +00:00
|
|
|
|
2020-09-01 20:04:48 +00:00
|
|
|
user_service_provider.reset()
|
2015-06-10 09:00:43 +00:00
|
|
|
|
2020-09-01 20:04:48 +00:00
|
|
|
users_service2 = user_service_provider()
|
|
|
|
assert users_service2 is not user_service1
|