mirror of
https://github.com/ets-labs/python-dependency-injector.git
synced 2024-11-22 09:36:48 +03:00
2bf3601695
* Add implementation and typing stubs * Make some refactoring and add tests * Pin ubuntu version to 18.04 * Add docs and example * Add changelog * Add container docs
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
|