Microsoft Bot Builder 4.2.2中缺少ITurnContext Service集合 [英] ITurnContext Service collection missing in Microsoft bot builder 4.2.2

查看:55
本文介绍了Microsoft Bot Builder 4.2.2中缺少ITurnContext Service集合的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试向使用Microsoft bot框架v 4.2.2创建的bot添加一些中间件代码.

I'm trying to add some middleware code to a bot I'm creating with microsoft bot framework v 4.2.2.

我可以在早期版本的builder中看到,您可以在ITurnContext的'Services'属性内将服务添加到服务集合中,但是该服务不再存在,并且我找不到任何文档来详细说明删除.

I can see in previous versions of builder, you're able to add services to the service collection within the 'Services' property of ITurnContext, however it no longer is present, and I can't find any documentation to detail the removal.

public async Task OnTurn(ITurnContext context, MiddlewareSet.NextDelegate next)
{
    // some middleware method in bot builder 4.0
    context.Services.Add(SOME_KEY, someTService);
    await next();
}

我想用我的机器人做同样的事情,所以如果有人知道这可能要到哪里,我将非常感谢您提供的信息!

I'd like to be doing the same thing with my bot, so if anyone knows where this might have got to I'd much appreciate the info!

谢谢

尼克

推荐答案

已将其移至名为TurnState的属性中.

It has been moved to a property called TurnState;

https://docs.microsoft .com/en-us/dotnet/api/microsoft.bot.builder.turncontext.turnstate

因此,代码如下所示:

public async Task OnTurn(ITurnContext context, MiddlewareSet.NextDelegate next,  CancellationToken cancellationToken = new CancellationToken())
{
    // some middleware method in bot builder 4.2.2
    context.TurnState.Add(SOME_KEY, someTService);
    await next();
}

这篇关于Microsoft Bot Builder 4.2.2中缺少ITurnContext Service集合的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆