我已经在我的机器人应用程序中实现了依赖注入。
LuisDialog.cs
CarInventory
LuisDialog.cs-销售意向
[LuisModel("xxx", "xxx")]
[Serializable]
public class LUISDialog : LuisDialog<object>
{
private LuisDialog<object> _luisDialog;
private ISalesDialog _salesDialog;
public LUISDialog(LuisDialog<object> luisDialog, ISalesDialog salesDialog)
{
_luisDialog = luisDialog;
_salesDialog = salesDialog;
}
}
MessagesController.cs
[LuisIntent("Sales")]
public async Task Sales(IDialogContext context, LuisResult result)
{
// Pass request to service for answer
await context.PostAsync(_salesDialog.GetAnswer(result.Query));
}
我的问题: 感觉像是DI破坏了bot框架的流程。具体来说,是一种用于验证需要路由到什么意图的机制。
我的应用程序可以通过模拟器正常加载。但是,在键入特定于销售意图的条目时,它击中了我的LUISDialog类中的构造函数(按预期方式)落入WebAPIconfig.cs中,并在JsonConvert.DefaultSettings调用上失败:
[BotAuthentication]
public class MessagesController : ApiController
{
private LuisDialog<object> _luisDialog;
private ISalesDialog _salesDialog;
public MessagesController(LuisDialog<object> luisDialog, ISalesDialog salesDialog)
{
_luisDialog = luisDialog;
_salesDialog = salesDialog;
}
/// <summary>
/// POST: api/Messages
/// Receive a message from a user and reply to it
/// </summary>
public async Task<HttpResponseMessage> Post([FromBody]Activity activity)
{
var container = UWServiceInfrastructure.Infrastructure.EngineContext.Current.ContainerManager.Container;
if (activity.Type == ActivityTypes.Message)
{
await Conversation.SendAsync(activity, () => new LUISDialog(_luisDialog, _salesDialog));
}
else
{
HandleSystemMessage(activity);
}
var response = Request.CreateResponse(HttpStatusCode.OK);
return response;
}
没有错误信息。我刚收到一个500的响应码。当我注释掉LUISDialog构造函数中的注入片段时,正确选择了意图。不知道我在这里可能会错过什么。