3

I use 2 LUIS models in 1 LUIS Dialog via attributes

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

I need to get these models from the config file. In Autofac I can only register 1

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

How can I set up multiple Luis models from a config?

Ezequiel Jadib
  • 14,767
  • 2
  • 38
  • 43
BotDev
  • 43
  • 5

1 Answers1

1

I don't think that will work since the LuisModel is being injected to the LuisService you are registering (which probably is the next line in your configuration) and the LuisService is just expecting a single model and not an array of them.

The way I can think this could work is, instead of registering the model(s) to the Autofac container, you should register multiple LuisService defining the value of the model parameter of the constructor to each of your models (see this).

In that way, when you resolve your LuisDialog based dialog, it will inject multiple ILuisService (see this) as it's prepared to receive an array of services.

I haven't tried this, but you could see if something like this works:

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()

Alternatively, you can use RegisterInstance and register the instances of the LuisService with their specific model.

Ezequiel Jadib
  • 14,767
  • 2
  • 38
  • 43