Microsoft Bot框架状态管理

时间:2017-12-05 09:41:20

标签: c# azure botframework

我们正在更新我们的MBF bot,以便在Azure Table Store中管理其状态。我们根据文档更改了代码以注册我们的表存储提供程序:

protected void Application_Start()
{
        GlobalConfiguration.Configure(WebApiConfig.Register);
        var builder = new ContainerBuilder();
        var store = new TableBotDataStore("...");

        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();

        var config = GlobalConfiguration.Configuration;

        var container = builder.Build();
        config.DependencyResolver = new AutofacWebApiDependencyResolver(container);
}

现在,在对话框中我们使用以下内容来存储和加载用户数据:

context.PrivateConversationData.SetValue<UserData>(UserDataRepositoryKey, userData);

有趣的是,对话状态似乎得到维护,但我们看不到任何东西是我们的Azure表,我真的怀疑任何调用是否正在进入该存储。关于如何以正确的方式使用状态,文档非常不清楚。

问题:

  1. 我们的容器注册看起来是否正确?它应该在app_start还是我们应该为每个请求注册它?

  2. 我们是否在会话期间使用正确的方法存储状态?

1 个答案:

答案 0 :(得分:5)

您似乎没有更新Conversation容器。您需要使用Conversation.UpdateContainer方法。

Conversation.UpdateContainer(
           builder =>
           {
               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();


           });

有关该主题的文档可在https://docs.microsoft.com/en-us/bot-framework/dotnet/bot-builder-dotnet-state-azure-table-storage找到,样本可在https://github.com/Microsoft/BotBuilder-Azure/tree/master/CSharp/Samples/AzureTable找到。

相关问题