Created
January 25, 2018 02:39
-
-
Save dcomartin/312b43a5c162022a3c5c1c7ba932f3a6 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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