mirror of
https://github.com/ets-labs/python-dependency-injector.git
synced 2024-11-22 17:47:02 +03:00
24 lines
504 B
Python
24 lines
504 B
Python
"""`Singleton` provider resetting example."""
|
|
|
|
from dependency_injector import containers, providers
|
|
|
|
|
|
class UserService:
|
|
...
|
|
|
|
|
|
class Container(containers.DeclarativeContainer):
|
|
|
|
user_service_provider = providers.Singleton(UserService)
|
|
|
|
|
|
if __name__ == '__main__':
|
|
container = Container()
|
|
|
|
user_service1 = container.user_service_provider()
|
|
|
|
container.user_service_provider.reset()
|
|
|
|
users_service2 = container.user_service_provider()
|
|
assert users_service2 is not user_service1
|