2020-09-01 20:04:48 +00:00
|
|
|
"""`Singleton` provider resetting example."""
|
2015-06-10 09:00:43 +00:00
|
|
|
|
2020-09-03 20:56:01 +00:00
|
|
|
from dependency_injector import containers, 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-03 20:56:01 +00:00
|
|
|
class Container(containers.DeclarativeContainer):
|
|
|
|
|
2021-02-05 23:17:44 +00:00
|
|
|
user_service = providers.Singleton(UserService)
|
2015-06-10 09:00:43 +00:00
|
|
|
|
|
|
|
|
2021-09-30 19:32:21 +00:00
|
|
|
if __name__ == "__main__":
|
2020-09-03 20:56:01 +00:00
|
|
|
container = Container()
|
|
|
|
|
2021-02-05 23:17:44 +00:00
|
|
|
user_service1 = container.user_service()
|
2015-06-10 09:00:43 +00:00
|
|
|
|
2021-02-05 23:17:44 +00:00
|
|
|
container.user_service.reset()
|
2015-06-10 09:00:43 +00:00
|
|
|
|
2021-02-05 23:17:44 +00:00
|
|
|
user_service2 = container.user_service()
|
2020-09-03 21:57:26 +00:00
|
|
|
assert user_service2 is not user_service1
|