I have seen a lot of articles recommending not to use the default bot state data storage because microsoft will certainly shutdown this service in march 2018.
I am currently developping a stateless bot and don't need any storage.
I have tried to create a fake one
internal class DummyDataStore : IBotDataStore<BotData>
{
public DummyDataStore()
{
}
public Task<bool> FlushAsync(IAddress key, CancellationToken cancellationToken)
{
return Task.FromResult(true);
}
public Task<BotData> LoadAsync(IAddress key, BotStoreType botStoreType, CancellationToken cancellationToken)
{
return Task.FromResult(new BotData());
}
public Task SaveAsync(IAddress key, BotStoreType botStoreType, BotData data, CancellationToken cancellationToken)
{
return Task.CompletedTask;
}
}
And registered it with autofac in global.asax
Conversation.UpdateContainer(
builder =>
{
//Registration of message logger
builder.RegisterType<BotMessageLogger>().AsImplementedInterfaces().InstancePerDependency();
//Registration of dummy data storage
var store = new DummyDataStore();
builder.Register(c => store).As<IBotDataStore<BotData>>().AsSelf().SingleInstance();
});
But it seems to mess with the context and bot doesn't respond to any context.wait() methods
I also tried this:
Conversation.UpdateContainer(
builder =>
{
var store = new InMemoryDataStore();
builder.Register(c => store)
.Keyed<IBotDataStore<BotData>>(AzureModule.Key_DataStore)
.AsSelf()
.SingleInstance();
});
Still have the warning
Dialogs are automatically serialized into the state store. The Bot Builder SDK itself is restful, and the state store is used to enable .Wait(methodName) to resume at the methodName on the next call.
If your bot is not concerned with persisting state across server restarts, you can use the
InMemoryDataStore: https://github.com/Microsoft/BotBuilder/blob/db2b8f860a3d8f7744a378930f93c4b0baa97978/CSharp/Library/Microsoft.Bot.Builder/ConnectorEx/BotData.cs#L90
builder.RegisterModule(new AzureModule(Assembly.GetExecutingAssembly()));
var store = new InMemoryDataStore();
builder.Register(c => store)
.Keyed<IBotDataStore<BotData>>(AzureModule.Key_DataStore)
.AsSelf()
.SingleInstance();
builder.Register(c => new CachingBotDataStore(store,
CachingBotDataStoreConsistencyPolicy.ETagBasedConsistency))
.As<IBotDataStore<BotData>>()
.AsSelf()
.InstancePerLifetimeScope();
Edit: You can also register the InMemoryDataStore without using the AzureModule:
var memorystore = new InMemoryDataStore();
builder
.RegisterType<InMemoryDataStore>()
.Keyed<IBotDataStore<BotData>>(typeof(ConnectorStore));
builder.Register(c => new CachingBotDataStore(memorystore, CachingBotDataStoreConsistencyPolicy.ETagBasedConsistency))
.As<IBotDataStore<BotData>>()
.AsSelf()
.SingleInstance();
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With