mirror of
https://github.com/ets-labs/python-dependency-injector.git
synced 2024-11-25 11:04:01 +03:00
2fe0e00cef
* Improve .traverse() typing stubs * Fix container.reset_singletons() * Add implementation, tests, and typing stubs * Add docs and example * Update changelog
24 lines
466 B
Python
24 lines
466 B
Python
"""`Singleton` provider resetting example."""
|
|
|
|
from dependency_injector import containers, providers
|
|
|
|
|
|
class UserService:
|
|
...
|
|
|
|
|
|
class Container(containers.DeclarativeContainer):
|
|
|
|
user_service = providers.Singleton(UserService)
|
|
|
|
|
|
if __name__ == '__main__':
|
|
container = Container()
|
|
|
|
user_service1 = container.user_service()
|
|
|
|
container.user_service.reset()
|
|
|
|
user_service2 = container.user_service()
|
|
assert user_service2 is not user_service1
|