Sponsor: Do you build complex software systems? See how NServiceBus makes it easier to design, build, and manage software systems that use message queues to achieve loose coupling. Get started for free.

Blog Post Series:
- Part 1 – Practical Orleans
- Part 2 – Grains and Silos
- Part 3 – Smart Cache Pattern
- Part 4 – Event Sourced Grain
- Part 5 – EventStore for Grain Persistence
Video Tutorial
State Holder Grain
The idea is we are going to create a Grain that will be used for holding/containing our state. There are just two methods, setting and getting our state as defined inIStateHolderGrain<T>
Implementation
For this example, I’m creating a POCOCustomerState
to hold some customer data.
Then create a ICustomerGrain
that just extends IStateHolderGrain
where T is our POCO CustomerState
.
Our concrete class CustomerGrain
that implements that new ICustomerGrain
.
Lastly I created a CustomerStateService which just contains some static methods that create and retrieve our POCO.
Usage
As per my previous post, I’m using ASP.NET Core with Botwin Middleware for a route endpoint. From here I can use theCustomerStateService
to create and fetch out our data.