我一直试图从MessagesController将服务传递给LuisDialog,如下所示:
public async Task<HttpResponseMessage> Post([FromBody]Activity activity)
...
await Conversation.SendAsync(activity, () => new ActionDialog(botService));
Run Code Online (Sandbox Code Playgroud)
使用依赖注入将botService注入到MessageController中.
当我开始机器人对话时,我收到一个错误:
在程序集'ThetaBot.Services,Version = 1.0.0.0,Culture = neutral,PublicKeyToken = null'中键入'ThetaBot.Services.BotService'未标记为可序列化.
寻找解决方案我可以找到:https: //github.com/Microsoft/BotBuilder/issues/106
我现在更了解你的问题.我们对服务对象有类似的问题,我们希望从容器而不是序列化的blob中实例化.以下是我们如何在容器中注册这些对象 - 我们在对所有具有Key_DoNotSerialize键的对象进行反序列化时应用特殊处理:
builder
.RegisterType<BotToUserQueue>()
.Keyed<IBotToUser>(FiberModule.Key_DoNotSerialize)
.AsSelf()
.As<IBotToUser>()
.SingleInstance();
Run Code Online (Sandbox Code Playgroud)
但是,我找不到详细说明如何在现有Bot Framework模块中注册自己的依赖项的示例或文档.
我还发现了https://github.com/Microsoft/BotBuilder/issues/252,它表明应该可以从容器中实例化对话框.
我试过这个建议:
Func<IDialog<object>> makeRoot = () => actionDialog;
await Conversation.SendAsync(activity, makeRoot);
Run Code Online (Sandbox Code Playgroud)
和...一起:
builder
.RegisterType<ActionDialog>()
.Keyed<ActionDialog>(FiberModule.Key_DoNotSerialize)
.AsSelf()
.As<ActionDialog>()
.SingleInstance();
Run Code Online (Sandbox Code Playgroud)
这不起作用.
我也尝试过:
var builder = new ContainerBuilder();
builder.RegisterModule(new DialogModule_MakeRoot());
// My application module
builder.RegisterModule(new ApplicationModule());
using (var container = builder.Build())
using (var scope …
Run Code Online (Sandbox Code Playgroud)