在我的消息控制器,我想检查某个对话框是否是堆栈的传入消息上之前将其分派到一个对话框,这样我就可以抑制某些条件行为.我尝试IDialogStack按照这个答案解决,像这样:
public async Task<HttpResponseMessage> Post([FromBody] Activity incomingMessage)
{
try
{
if (incomingMessage.Type == ActivityTypes.Message)
{
using (var scope = DialogModule.BeginLifetimeScope(Conversation.Container, activity))
{
var stack = scope.Resolve<IDialogStack>();
}
...
Run Code Online (Sandbox Code Playgroud)
这是在我的Global.asax中注册的模块:
private void RegisterBotModules()
{
var builder = new ContainerBuilder();
builder.RegisterModule(new DialogModule());
builder.RegisterModule(new ReflectionSurrogateModule());
builder.RegisterModule(new DialogModule_MakeRoot());
builder.RegisterModule<GlobalMessageHandler>();
builder.RegisterModule(new AzureModule(Assembly.GetExecutingAssembly()));
var store = new TableBotDataStore(/*connection string*/);
builder.Register(c => store)
.Keyed<IBotDataStore<BotData>>(AzureModule.Key_DataStore)
.AsSelf()
.SingleInstance();
builder.Register(c => new CachingBotDataStore(store, CachingBotDataStoreConsistencyPolicy.ETagBasedConsistency))
.As<IBotDataStore<BotData>>()
.AsSelf()
.InstancePerLifetimeScope();
builder.Update(Conversation.Container);
var config = GlobalConfiguration.Configuration;
config.DependencyResolver = new AutofacWebApiDependencyResolver(Conversation.Container);
}
Run Code Online (Sandbox Code Playgroud)
但是,我得到以下例外:
{"激活特定注册时发生错误.有关详细信息,请参阅内部异常.注册:Activator = IDialogTask(DelegateActivator),Services = [Microsoft.Bot.Builder.Dialogs.Internals.IDialogStack,Microsoft.Bot.Builder. Dialogs.Internals.IDialogTask],Lifetime = Autofac.Core.Lifetime.CurrentScopeLifetime,Sharing = Shared,Ownership = OwnedByLifetimeScope --->对象引用未设置为对象的实例.(有关详细信息,请参阅内部异常.)"
内部异常:
"你调用的对象是空的."
"at Autofac.Core.Resolving.InstanceLookup.Activate(IEnumerable
1 parameters)\r\n at Autofac.Core.Resolving.InstanceLookup.<Execute>b__5_0()\r\n at Autofac.Core.Lifetime.LifetimeScope.GetOrCreateAndShare(Guid id, Func1 creator)\ r \n在Autofac.Core.Resolving.InstanceLookup.Execute()\ r \n在Autofac.Core.Resolving.ResolveOperation.GetOrCreateInstance(ISharingLifetimeScope currentOperationScope, IComponentRegistration注册,IEnumerable1 parameters)\r\n at Autofac.Core.Resolving.ResolveOperation.Execute(IComponentRegistration registration, IEnumerable1参数)\ r \n在Autofac.Core.Lifetime.LifetimeScope.ResolveComponent(IComponentRegistration注册,IEnumerable1 parameters)\r\n at Autofac.ResolutionExtensions.TryResolveService(IComponentContext context, Service service, IEnumerable1参数,对象和实例)\ r \n在Autofac.ResolutionExtensions.ResolveService(IComponentContext context,Service service,IEnumerable)1 parameters)\r\n at Autofac.ResolutionExtensions.Resolve[TService](IComponentContext context, IEnumerable1参数)\ r \n在Autofac.ResolutionExtensions.Resolve [TService](IComponentContext context)\ r \n,在D:\ Source\Repos\QUO_Cognitive_Quoting\Src \的Progressive.CQBot.Controllers.MessagesController.d__0.MoveNext()中CQBot\Controllers\MessagesController.cs:第33行"
链接答案中的建议是否已弃用?我缺少一些模块注册吗?我会很感激任何方向!
该BotData需要在范围上解决之前加载IDialogStack.
请尝试以下方法:
using (var scope = DialogModule.BeginLifetimeScope(Conversation.Container, activity))
{
var botData = scope.Resolve<IBotData>();
await botData.LoadAsync(new System.Threading.CancellationToken());
var stack = scope.Resolve<IDialogStack>();
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
847 次 |
| 最近记录: |