配置中的多个 LUIS 模型

Multiple LUIS models from config

我通过属性在 1 个 LUIS 对话框中使用 2 个 LUIS 模型

[LuisModel("model1", "")]    
[LuisModel("model2", "")]
[Serializable]
public class LuisDialog

我需要从配置文件中获取这些模型。 在 Autofac 中我只能注册 1

builder.Register(c => new LuisModelAttribute("model1", ""))...

如何从一个配置中设置多个 Luis 模型?

我认为这不会起作用,因为 LuisModel 被注入到您正在注册的 LuisService 中(这可能是您配置中的下一行)并且 LuisService 只是期待单个模型,而不是它们的数组。

我认为这可行的方法是,与其将模型注册到 Autofac 容器,不如注册多个 LuisService 定义模型参数的值每个模型的构造函数(参见 this)。

这样,当您解析基于 LuisDialog 的对话框时,它将注入多个 ILuisService(请参阅 this),因为它已准备好接收一系列服务。

我还没试过,但你可以看看这样的方法是否有效:

var model1 = new LuisModelAttribute("model1", "");
var model2 = new LuisModelAttribute("model2", "");

builder.RegisterType<LuisService>()
       .WithParameter("model", model1)
       .Keyed<ILuisService>(FiberModule.Key_DoNotSerialize)
       .AsImplementedInterfaces()
       .SingleInstance(); or // .InstancePerLifetimeScope()

builder.RegisterType<LuisService>()
       .WithParameter("model", model2)
       .Keyed<ILuisService>(FiberModule.Key_DoNotSerialize)
       .AsImplementedInterfaces()
       .SingleInstance(); or // .InstancePerLifetimeScope()

或者,您可以使用 RegisterInstance 并使用其特定模型注册 LuisService 的实例。