mirror of
https://github.com/ets-labs/python-dependency-injector.git
synced 2024-11-25 11:04:01 +03:00
24 lines
525 B
Python
24 lines
525 B
Python
"""Container reset singletons context manager example."""
|
|
|
|
from dependency_injector import containers, providers
|
|
|
|
|
|
class Container(containers.DeclarativeContainer):
|
|
|
|
service = providers.Singleton(object)
|
|
|
|
|
|
if __name__ == "__main__":
|
|
container = Container()
|
|
|
|
service1 = container.service()
|
|
|
|
with container.reset_singletons():
|
|
service2 = container.service()
|
|
|
|
service3 = container.service()
|
|
|
|
assert service1 is not service2
|
|
assert service2 is not service3
|
|
assert service3 is not service1
|