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