python-dependency-injector/examples/providers/singleton_delegation.py

14 lines
448 B
Python
Raw Normal View History

2015-09-02 16:06:09 +00:00
"""`di.Singleton` providers delegation example."""
2015-09-02 16:06:09 +00:00
import dependency_injector as di
# Some singleton provider and few delegates of it:
2015-09-02 16:06:09 +00:00
singleton_provider = di.Singleton(object)
singleton_provider_delegate1 = singleton_provider.delegate()
2015-09-02 16:06:09 +00:00
singleton_provider_delegate2 = di.Delegate(singleton_provider)
# Making some asserts:
assert singleton_provider_delegate1() is singleton_provider
assert singleton_provider_delegate2() is singleton_provider