Class ShortLivedState<T>
Keeps states of one type under one key prefix in the registered IShortLivedStore, each for the same lifetime: adds them under new random IDs, and gets, takes and removes them by ID. An ID that does not have the form of one (see IsWellFormed(string?)) is not looked up.
Namespace: Singulink.Net.Http.Api.Service
Assembly: Singulink.Net.Http.Api.Service.dll
Syntax
public class ShortLivedState<T> where T : class
Type Parameters
| Name | Description |
|---|---|
| T | The type of the states. |
Remarks
States are stored as JSON with the specified JsonTypeInfo<T>, as by ShortLivedStoreExtensions. A stored value that cannot be read as the state is treated as missing and logged as a warning to the logger, if one is given.
Constructors
| Name | Description |
|---|---|
| ShortLivedState(IShortLivedStore, string, JsonTypeInfo<T>, TimeSpan, ILogger?) | Initializes a new instance of the ShortLivedState<T> class. |
Properties
| Name | Description |
|---|---|
| Lifetime | Gets how long each state is kept after it is added. |
Methods
| Name | Description |
|---|---|
| AddAsync(T, CancellationToken) | Adds a state under a new random ID and returns the ID, which the next step of a flow presents. |
| GetAsync(string, CancellationToken) | Gets the state with the specified ID, or returns null if there is none, or the ID does not have the form of an ID. |
| RemoveAsync(string, CancellationToken) | Removes the state with the specified ID, if there is one. Nothing is removed if the ID does not have the form of an ID. |
| TakeAsync(string, CancellationToken) | Gets and removes the state with the specified ID, or returns null if there is none, or the ID does not have the form of an ID. A state is returned at most once, even when it is taken by concurrent calls. |