FormFlow IDialog<T> 是否需要 Chain.From

Is Chain.From Required for FormFlow IDialog<T>

例如 SandwichBot,使用 Chain.From 到 return IDialog<T> 用于 SendAsync,像这样:

    internal static IDialog<SandwichOrder> MakeRootDialog()
    {
        return Chain.From(() => FormDialog.FromForm(SandwichOrder.BuildForm));
    }

我可以看到 Chain.FromFormDialog.FromForm 推送和弹出 IFormDialog<T>,return,但我不确定这样做有什么好处。但是,聊天机器人在没有 Chain.From 的情况下仍然可以工作,如下所示:

    internal static IDialog<SandwichOrder> MakeRootDialog()
    {
        return FormDialog.FromForm(SandwichOrder.BuildForm);
    }

由于示例使用 Chain.From,这让我觉得它可能以某种方式被要求或推荐。 Chain.From 的基本原理是什么?在哪里需要它?如果没有它,更简单的语法有什么缺点?

SimpleSandwichBot I believe that it doesn't make sense to have the Chain.From, however I suspect that was done to allow a seamless transition to the AnnotatedSandwichBot 中,Chain 使用得更多一些。

就我个人而言,我不经常使用 Chain,除非我需要将一些非常简单的东西放在一起并且我不想创建一个对话框,因为它很容易变得复杂到 read/follow。

使用 Chain 您可以隐式管理对话框堆栈。但是,显式管理对话堆栈 () 似乎更适合编写较大的对话。创建新对话框更加冗长(尤其是在 C# 中),但我相信它可以更好地组织解决方案和代码。

我认为没有地方需要 Chain,因为它没有提供任何独特的东西,只是提供了一个可在 LINQ 查询语法中使用的流畅界面。

我看到的缺点主要是如果你想创建一些大的东西,结果代码的复杂性。如果我没记错的话,根据您的使用方式,也有可能出现序列化问题。

来自docs

The Chain methods provide a fluent interface to dialogs that is usable in LINQ query syntax. The compiled form of LINQ query syntax often leverages anonymous methods. If these anonymous methods do not reference the environment of local variables, then these anonymous methods have no state and are trivially serializable. However, if the anonymous method captures any local variable in the environment, the resulting closure object (generated by the compiler) is not marked as serializable. The Bot Builder will detect this situation and throw a ClosureCaptureException to help diagnose the issue.