我正在使用一个 autofac json 文件,其中列出了我的所有依赖项。以下是 json 文件供参考。
{
"defaultAssembly": "DigitalAssistant.Wharf",
"components": [
{
"type": "DigitalAssistant.Dialogs.RootDialog, DigitalAssistant.Wharf",
"services": [
{
"type": "Microsoft.Bot.Builder.Dialogs.IDialog, Microsoft.Bot.Builder"
}
],
"injectProperties": true,
"instanceScope": "perlifetimescope"
}
]
}
我的 RootDialog 类如下:
[Serializable]
public class RootDialog : IDialog<object>
{
public Task StartAsync(IDialogContext context)
{
context.Wait(MessageReceivedAsync);
return Task.CompletedTask;
}
private async Task MessageReceivedAsync(IDialogContext context, IAwaitable<object> result)
{
var activity = await result as Activity;
// Calculate something for us to return
int length = (activity.Text ?? string.Empty).Length;
// Return our reply to the user
await context.PostAsync($"You sent {activity.Text} which was {length} characters");
context.Wait(MessageReceivedAsync);
}
}
在 MessageController.cs 中,解决依赖关系如下:
public async Task<HttpResponseMessage> Post([FromBody]Activity activity)
{
if (activity.GetActivityType() == ActivityTypes.Message)
{
using (var scope = DialogModule.BeginLifetimeScope(Conversation.Container, activity))
{
var dialog = scope.Resolve<IDialog<object>>();
await Conversation.SendAsync(activity, () => dialog);
}
}
else
{
HandleSystemMessage(activity);
}
var response = Request.CreateResponse(HttpStatusCode.OK);
return response;
}
问题是,何时通过 Global.asax 中的以下代码注册模块:
var config = new ConfigurationBuilder();
config.AddJsonFile("autofac.json");
var module = new ConfigurationModule(config.Build());
builder.RegisterModule(module);
它给出的错误与类型 DigitalAssistant.Dialogs.RootDialog 不可分配给服务 Microsoft.Bot.Builder.Dialogs.IDialog 一样。
我在这里缺少什么,请帮忙。