2015-03-30 16:11:33 +03:00
|
|
|
"""`NewInstance` and `Singleton` providers example."""
|
|
|
|
|
|
|
|
from objects.providers import NewInstance
|
|
|
|
from objects.providers import Singleton
|
|
|
|
|
|
|
|
|
2015-04-14 23:17:53 +03:00
|
|
|
# NewInstance provider creates new instance of specified class on every call.
|
2015-03-30 16:11:33 +03:00
|
|
|
new_object = NewInstance(object)
|
|
|
|
|
|
|
|
object_1 = new_object()
|
|
|
|
object_2 = new_object()
|
|
|
|
|
|
|
|
assert object_1 is not object_2
|
|
|
|
|
2015-04-14 23:17:53 +03:00
|
|
|
# Singleton provider creates new instance of specified class on first call
|
|
|
|
# and returns same instance on every next call.
|
2015-03-30 16:11:33 +03:00
|
|
|
single_object = Singleton(object)
|
|
|
|
|
|
|
|
single_object_1 = single_object()
|
|
|
|
single_object_2 = single_object()
|
|
|
|
|
|
|
|
assert single_object_1 is single_object_2
|