Skip to content

IDurableStateManager Methods

Manages a grain's durable state, whose named components share a journal and write acknowledgement boundary.

GetOrAddState(string)

abstract
public abstract TState GetOrAddState<TState>(string name)
Gets an existing state component or creates it using the registered implementation of its application contract.

Parameters

namestring
The stable, ordinal, case-sensitive state name.

Returns

The existing or newly created state instance.

Exceptions

System.InvalidOperationException
The name has an incompatible state type, the contract is not registered, or initialization has begun and the state does not exist.

TryGetState(string, TState?)

abstract
public abstract bool TryGetState<TState>(string name, out TState? state)
Attempts to retrieve an existing state component without creating it.

Parameters

namestring
The stable, ordinal, case-sensitive state name.
stateTState?
The existing state, if found.

Returns

true if a compatible state exists; otherwise, false.

Exceptions

System.InvalidOperationException
The name has an incompatible state type.

WriteStateAsync(CancellationToken)

abstract
public abstract ValueTask WriteStateAsync(CancellationToken cancellationToken = default(CancellationToken))
Persists pending changes to the shared journal.

Parameters

cancellationTokenCancellationToken
The token used to cancel the caller's wait.

Returns

A task representing the write acknowledgement.