簡體   English   中英

來自config的多個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 ,為每個模型定義構造函數的模型參數的值(參見本文 )。

這樣,當您解決基於LuisDialog的對話框時,它將注入多個ILuisService (請參閱此內容 ),因為它准備接收一組服務。

我沒試過這個,但你可以看看這樣的東西是否有效:

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的實例注冊到其特定模型。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM