Singleton¶
uzi.providers.Singleton
¶
Bases: Factory[T_Injected, nodes._T_SingletonNode]
A Singleton provider is a Factory that returns same instance on every
call.
On the first request, the given factory will be called to create the instance which will be stored and returned on subsequent requests.
Attributes:
| Name | Type | Description |
|---|---|---|
is_thread_safe |
bool
|
Indicates whether to wrap the factory call with a
|
thread_safe(is_thread_safe: bool = True) -> Self
¶
Mark/Unmark this provider as thread safe. Updates the is_thread_safe
attribute.
is_thread_safe indicates whether to wrap the factory call with a Lock
to prevent simultaneous instance create when injecting from multiple threads.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
is_thread_safe |
bool
|
|
True
|
Returns:
| Name | Type | Description |
|---|---|---|
self |
Provider
|
this provider |