Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
31 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
"""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 |