I didn’t found the documentation really clear on the steps involved when using Grain Persistence in combination with PostgreSQL.
So here is my attempt to describe the process:
- Add a reference to the following NuGet packages:
- Update the cluster configuration to add the storage:
- Invariant should be set to ‘npgsql’
- ConnectionString should be set to the connection to the PostgreSQL instance you want to use
- UseJsonFormat should be set to true as PostgreSQL has good Json support.
- Let your grain inherit from Grain<> and specify a state object:
- Add a StorageProvider attribute on top of your Grain and set the name to the storage name you used inside the cluster config
- In our example we had set this to ‘OrleansStorage’:
- Execute the PostgreSQL-Main.sql and PostgreSQL-Persistence.sql scripts inside the OrleansAdoNetContent/PostgreSQL folder to create the necessary database objects
- Now you are good to go!