Skip to content

Instantly share code, notes, and snippets.

@dcomartin
Created January 25, 2018 02:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dcomartin/312b43a5c162022a3c5c1c7ba932f3a6 to your computer and use it in GitHub Desktop.
Save dcomartin/312b43a5c162022a3c5c1c7ba932f3a6 to your computer and use it in GitHub Desktop.
public interface IStateHolderGrain<T> : IGrainWithGuidKey
{
Task<T> GetItem();
Task<T> SetItem(T obj);
}
public class StateHolder<T>
{
public StateHolder() : this(default(T))
{
}
public StateHolder(T value)
{
Value = value;
}
public T Value { get; set; }
}
public abstract class StateHolderGrain<T> : Grain<StateHolder<T>>,
IStateHolderGrain<T>
{
public Task<T> GetItem()
{
return Task.FromResult(State.Value);
}
public async Task<T> SetItem(T item)
{
State.Value = item;
await WriteStateAsync();
return State.Value;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment