[英]How to use context.Forward with autofac
I am trying to build a bot using Microsoft Bot Framework and Autofac. 我正在尝试使用Microsoft Bot Framework和Autofac构建机器人。 I have a service which is shared between 2 Dialogs and the first Dialog instantiates the other based on a user response.
我有一个服务,它在2个Dialogs之间共享,第一个Dialog根据用户响应实例化另一个。 Inside my Dialog I invoke this line:
在我的Dialog中,我调用了这一行:
await context.Forward(new StepDialog(_productProvider, _groups, _products, 0), ResumeAfter, new Activity { Text = category }, CancellationToken.None);
But I don't think this is right. 但我不认为这是对的。 In my controller, I do this:
在我的控制器中,我这样做:
// Create our scope
using (var scope = DialogModule.BeginLifetimeScope(Conversation.Container, model))
{
// Create our conversation
await Conversation.SendAsync(model, () => scope.Resolve<IDialog<object>>());
};
So I assume that I have to do something similar to get the instance of my StepDialog while maintaining the reference to the ProductProvider (which is my service). 所以我假设我必须做类似的事情来获取我的StepDialog的实例,同时保持对ProductProvider的引用(这是我的服务)。
I thought about passing the scope into the constructor of my initial Dialog but I have read that is a bad idea, so how can I go about this? 我考虑过将范围传递到我最初的Dialog的构造函数中,但我读过这是一个坏主意,所以我该如何解决这个问题呢?
One idea that I have seen working pretty well is to use a Dialog Factory; 我见过的一个很好的想法就是使用Dialog Factory; so you inject that into your dialog and use it to resolve other dialogs.
因此,您将其注入对话框并使用它来解析其他对话框。
In the ContosoFlowers sample you will find a basic implementation of a Dialog Factory. 在ContosoFlowers示例中,您将找到Dialog Factory的基本实现。 Below some reference links:
下面是一些参考链接:
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.