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

15 lines
485 B
Python
Raw Normal View History

"""`Singleton` providers delegation example."""
from objects.providers import Singleton
from objects.providers import Delegate
# Some singleton provider and few delegates of it:
singleton_provider = Singleton(object)
singleton_provider_delegate1 = singleton_provider.delegate()
singleton_provider_delegate2 = Delegate(singleton_provider)
# Making some asserts:
assert singleton_provider_delegate1() is singleton_provider
assert singleton_provider_delegate2() is singleton_provider