mirror of
https://github.com/ets-labs/python-dependency-injector.git
synced 2024-11-29 04:53:59 +03:00
19 lines
595 B
Python
19 lines
595 B
Python
"""`DelegatedSingleton` providers example."""
|
|
|
|
from dependency_injector import providers
|
|
|
|
|
|
# Some delegated singleton provider:
|
|
singleton_provider = providers.DelegatedSingleton(object)
|
|
registry = providers.DelegatedSingleton(dict,
|
|
object1=singleton_provider,
|
|
object2=singleton_provider)
|
|
|
|
# Getting several references to singleton object:
|
|
registry = registry()
|
|
singleton_object1 = registry['object1']()
|
|
singleton_object2 = registry['object2']()
|
|
|
|
# Making some asserts:
|
|
assert singleton_object1 is singleton_object2
|