psibr / REstate

Portable state-flows (state-machine based workflows)
MIT License
36 stars 7 forks source link

Controlling backing store for state machines (in memory store) #56

Closed ppittle closed 6 years ago

ppittle commented 6 years ago

I'm working on creating an Agent, but I want to be able to control if the state is stored in Redis ( prod / qa) or In Memory (local dev / unit tests).

I am able to configure my IAgent to use Redis:

internal class RedisREStateBackingStore : IRegisterREStateBackingStore
    {
        private readonly IRedisDatabaseFactory _databaseFactory;

        public RedisREStateBackingStore(IRedisDatabaseFactory databaseFactory)
        {
            _databaseFactory = databaseFactory;
        }

        public void RegisterBackingStore(IAgent restateAgent)
        {
            var redisRepositoryComponent = new RedisRepositoryComponent(_databaseFactory.CreateDatabase());
            restateAgent.Configuration.RegisterComponent(redisRepositoryComponent);
        }
    }

How would I configure an IAgent to keep state in memory?

aidapsibr commented 6 years ago

REstate sets up some defaults when connected to a kernel, whether that is the built-in one or Ninject. Those defaults include an InMemoryRepositoryComponent.

When you register the Redis component it replaces the binding of the in-memory repository. So, the easiest way to configure it to be in-memory is just to not register the Redis component.

ppittle commented 6 years ago

That did it, thanks!