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