上篇文章介绍了什么是Activity,Turn,TurnContext和BotAdapter,这篇文章我们看看这些东西是如何窜起来的,他们是如何处理用户发给bot的消息的。
我们以一个最简单的bot,echo bot为例子,所谓的echo bot就是用户发什么消息,它就照样回复一条消息。为了简单起见,大家可以先安装VS2019的一个扩展插件BotBuilderVSIX.vsix template,然后创建一个NET core 3.1的Echo bot。
可以看到这个模板为什么创建了一个项目,我们先到Startup.cs看一下:
// Create the Bot Framework Adapter with error handling enabled.
services.AddSingleton<IBotFrameworkHttpAdapter, AdapterWithErrorHandler>();
// Create the bot as a transient. In this case the ASP Controller is expecting an IBot.
services.AddTransient<IBot, EchoBot>();
可以看到DI了两个类,值得注意的是,AdapterWithErrorHandler
使用的是Singleton,而EchoBot
使用的是Transient&#x