什么是Microsoft Bot Framework C#中的DialogModule.BeginLifeTimeScope?

什么是Microsoft Bot Framework C#中的DialogModule.BeginLifeTimeScope?,c#,dependency-injection,inversion-of-control,autofac,botframework,C#,Dependency Injection,Inversion Of Control,Autofac,Botframework,我试图理解Proactive bot示例,其中我们创建一个作用域,加载对话框堆栈,在其间中断它,并执行中断的一个。 谁能解释一下依赖注入中的作用域是什么。我是 C#中的依赖项注入和Autofac的新功能 1) DialogModule.BeginLifetimeScope(Conversation.Container // Create a scope that can be used to work with state from bot framework. using (var s

我试图理解Proactive bot示例,其中我们创建一个作用域,加载对话框堆栈,在其间中断它,并执行中断的一个。 谁能解释一下依赖注入中的作用域是什么。我是 C#中的依赖项注入和Autofac的新功能

1)
DialogModule.BeginLifetimeScope(Conversation.Container

// Create a scope that can be used to work with state from bot framework.
    using (var scope = DialogModule.BeginLifetimeScope(Conversation.Container, message))
    {
        var botData = scope.Resolve<IBotData>();
        await botData.LoadAsync(CancellationToken.None);

        // This is the dialog stack.
        var stack = scope.Resolve<IDialogStack>();

        // Create the new dialog and add it to the stack.
        var dialog =new SurveyDialog();
        stack.Call(dialog.Void<object, IMessageActivity>(), null);
        await stack.PollAsync(CancellationToken.None);

        // Flush the dialog stack back to its state store.
        await botData.FlushAsync(CancellationToken.None);        
    }
2) 什么是
var stack=scope.Resolve()做什么

// Create a scope that can be used to work with state from bot framework.
    using (var scope = DialogModule.BeginLifetimeScope(Conversation.Container, message))
    {
        var botData = scope.Resolve<IBotData>();
        await botData.LoadAsync(CancellationToken.None);

        // This is the dialog stack.
        var stack = scope.Resolve<IDialogStack>();

        // Create the new dialog and add it to the stack.
        var dialog =new SurveyDialog();
        stack.Call(dialog.Void<object, IMessageActivity>(), null);
        await stack.PollAsync(CancellationToken.None);

        // Flush the dialog stack back to its state store.
        await botData.FlushAsync(CancellationToken.None);        
    }
3)
等待stack.pollsync(CancellationToken.None)的是什么做什么

// Create a scope that can be used to work with state from bot framework.
    using (var scope = DialogModule.BeginLifetimeScope(Conversation.Container, message))
    {
        var botData = scope.Resolve<IBotData>();
        await botData.LoadAsync(CancellationToken.None);

        // This is the dialog stack.
        var stack = scope.Resolve<IDialogStack>();

        // Create the new dialog and add it to the stack.
        var dialog =new SurveyDialog();
        stack.Call(dialog.Void<object, IMessageActivity>(), null);
        await stack.PollAsync(CancellationToken.None);

        // Flush the dialog stack back to its state store.
        await botData.FlushAsync(CancellationToken.None);        
    }
4)
等待botData.FlushAsync(CancellationToken.None)的是什么做什么

// Create a scope that can be used to work with state from bot framework.
    using (var scope = DialogModule.BeginLifetimeScope(Conversation.Container, message))
    {
        var botData = scope.Resolve<IBotData>();
        await botData.LoadAsync(CancellationToken.None);

        // This is the dialog stack.
        var stack = scope.Resolve<IDialogStack>();

        // Create the new dialog and add it to the stack.
        var dialog =new SurveyDialog();
        stack.Call(dialog.Void<object, IMessageActivity>(), null);
        await stack.PollAsync(CancellationToken.None);

        // Flush the dialog stack back to its state store.
        await botData.FlushAsync(CancellationToken.None);        
    }
//创建一个作用域,该作用域可用于处理bot框架中的状态。
使用(var scope=DialogModule.BeginLifetimeScope(Conversation.Container,message))
{
var botData=scope.Resolve();
等待botData.LoadAsync(CancellationToken.None);
//这是对话框堆栈。
var stack=scope.Resolve();
//创建新对话框并将其添加到堆栈中。
var对话框=新建SurveyDialog();
调用(dialog.Void(),null);
wait stack.PollAsync(CancellationToken.None);
//将对话框堆栈刷新回其状态存储。
等待botData.FlushAsync(CancellationToken.None);
}

范围与可见性和寿命相关。在多线程应用程序中,有些对象可以跨线程使用,有些对象应该在处理完成时处理。bot框架sdk允许一次处理多条消息。bot builder用于处理消息的某些对象的作用域是会话id,并且一次只能处理一个在会话id上键入的活动

1) DialogModule.BeginLifetimeScope(Conversation.Container)做什么

BeginSlifetimeScope可在此处找到:基本上,此行使用autofac控制Bot框架使用的服务的创建、范围和生存期。请参阅此处:有关autofac生存期的更多信息

2) var stack=
scope.Resolve()的作用是什么做什么

// Create a scope that can be used to work with state from bot framework.
    using (var scope = DialogModule.BeginLifetimeScope(Conversation.Container, message))
    {
        var botData = scope.Resolve<IBotData>();
        await botData.LoadAsync(CancellationToken.None);

        // This is the dialog stack.
        var stack = scope.Resolve<IDialogStack>();

        // Create the new dialog and add it to the stack.
        var dialog =new SurveyDialog();
        stack.Call(dialog.Void<object, IMessageActivity>(), null);
        await stack.PollAsync(CancellationToken.None);

        // Flush the dialog stack back to its state store.
        await botData.FlushAsync(CancellationToken.None);        
    }
Autofac将此问题解析为已注册的IDialogTaskManager。DialogTasks[0]请参见此处:

3) 等待stack.PollAsync(CancellationToken.None)的是什么;是吗

这是IEventLoop上的内部BotFramework方法。这个实现(在DialogTask上)可以在这里找到:这个方法与bot框架的内部事件系统中的处理工作有关

4) 等待botData.FlushAsync(CancellationToken.None)的是什么;是吗


IBotData实现负责确保在调用.FlushAsync时将数据持久化到存储。

您读过吗?我已经读过了,但没有读到。你能解释我的4个问题吗@StevenI很抱歉,但我不熟悉机器人框架。没问题@Steven