State¶
The State provider stores a value as part of a context.
It is useful when you want to pass a value into your Container that other providers depend on.
Creating a state provider¶
The State provider does not accept any arguments when it created.
from that_depends import BaseContainer, providers
class Container(BaseContainer):
my_state: providers.State[int] = providers.State()
Initializing state¶
Note: If you try to resolve a
Stateprovider without initializing it first it will raise anStateNotInitializedError.
Nested state¶
The State provider will always resolve the last initialize value.