首页 > 解决方案 > 我的 global.asax.cs 文件中是否缺少用于连接到 Azure Cosmos 的依赖项?

问题描述

我是 Bot Framework 的新手,并且符合最佳实践,我一直在尝试连接到 Azure Cosmos DB 来管理状态数据。

下面的代码编译没有任何问题,但是当我尝试在 Azure 的测试 Web Bot 屏幕中测试机器人时,它会向 Bot 授权,但它没有连接,所以我无法测试数据库连接。

我一直在使用 SDK 的 v3 开发 Bot,并尝试通过删除最初关于 Cosmos DB 的注释行来修改开箱即用,但编译失败,所以一直在修改下面的代码,它可以编译,但是似乎没有启动机器人。

using System;
using Autofac;
using System.Web.Http;
using System.Configuration;
using System.Reflection;
using Microsoft.Bot.Builder.Azure;
using Microsoft.Bot.Builder.Dialogs;
using Microsoft.Bot.Builder.Dialogs.Internals;
using Microsoft.Bot.Connector;

namespace SimpleEchoBot
{
    public class WebApiApplication : System.Web.HttpApplication
    {
        protected void Application_Start()
        {
            // Bot Storage: This is a great spot to register the private state storage for your bot. 
            // We provide adapters for Azure Table, CosmosDb, SQL Azure, or you can implement your own!
            // For samples and documentation, see: https://github.com/Microsoft/BotBuilder-Azure

            var uri = new Uri(ConfigurationManager.AppSettings["uri"]);
            var key = ConfigurationManager.AppSettings["accesskey"];
            var store = new DocumentDbBotDataStore(uri, key);

            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();
                });
            GlobalConfiguration.Configure(WebApiConfig.Register);
        }
    }
}

我希望输出是 Bot 初始化,但没有这样做。

标签: botframeworkazure-cosmosdb

解决方案


推荐阅读