Multiple LUIS models from configuration

I am using 2 LUIS models in 1 LUIS Dialog via attributes

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

      

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

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

      

How do I set up multiple Luis models from a configuration?

+3


source to share


1 answer


I don't think this will work, as it LuisModel

is injected into LuisService

which you are registering (which is probably the next line in your config) and the LuisService just expects a single model, not an array of them.

How can I think this might work, instead of registering the model in the container Autofac

, you should register several LuisService

defining the value of the constructor model parameter for each of your models (see this ).

So, when resolving your dialog, LuisDialog

it will enter multiple ILuisService

(see this ) as it is 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 instances LuisService

with their specific model.

+1


source







All Articles