2015-11-23 12:43:11 +00:00
|
|
|
"""`Singleton` providers delegation example."""
|
2015-07-20 16:31:31 +00:00
|
|
|
|
2015-11-23 12:43:11 +00:00
|
|
|
from dependency_injector import providers
|
2015-07-20 16:31:31 +00:00
|
|
|
|
|
|
|
|
|
|
|
# Some singleton provider and few delegates of it:
|
2015-11-23 12:43:11 +00:00
|
|
|
singleton_provider = providers.Singleton(object)
|
2015-07-20 16:31:31 +00:00
|
|
|
singleton_provider_delegate1 = singleton_provider.delegate()
|
2015-11-23 12:43:11 +00:00
|
|
|
singleton_provider_delegate2 = providers.Delegate(singleton_provider)
|
2015-07-20 16:31:31 +00:00
|
|
|
|
|
|
|
# Making some asserts:
|
|
|
|
assert singleton_provider_delegate1() is singleton_provider
|
|
|
|
assert singleton_provider_delegate2() is singleton_provider
|