2021-02-05 22:14:10 +00:00
|
|
|
"""Container reset singletons example."""
|
|
|
|
|
|
|
|
from dependency_injector import containers, providers
|
|
|
|
|
|
|
|
|
|
|
|
class Container(containers.DeclarativeContainer):
|
|
|
|
|
|
|
|
service1 = providers.Singleton(object)
|
|
|
|
service2 = providers.Singleton(object)
|
|
|
|
|
|
|
|
|
2021-09-30 19:16:17 +00:00
|
|
|
if __name__ == "__main__":
|
2021-02-05 22:14:10 +00:00
|
|
|
container = Container()
|
|
|
|
|
|
|
|
service1 = container.service1()
|
|
|
|
service2 = container.service2()
|
|
|
|
|
|
|
|
container.reset_singletons()
|
|
|
|
|
|
|
|
assert service1 is not container.service1()
|
|
|
|
assert service2 is not container.service2()
|