I have an interface named IListener. Now I want to create a class that receives to instances of that interface.
public Controller(IListener listener1, IListener listener2)
{ ... }
The implementation of IListener needs a port. How can I determine the parameter name in the binding of IListener so I can choose my appropriate port? I think the callback could look like:
public Kernel()
{
Bind<IListener>()
.To<SyncUdpListener>()
.WithConstructorArgument("port", GetListenerPort);
}
private object GetListenerPort(IContext context, ITarget target)
{
var command = this.Get<Command>();
switch (...)
{
case "videoListener":
return command.VideoPort;
case "audioListener":
return command.AudioPort;
}
throw new Exception();
}
Where I need to fill in the parameter name in the switch statement.
Thanks in advance!
I`m not 100% percent sure what you want to achieve here. But if your controller looks like:
And with the following code:
You will get a controller with two
IListenerinstance with the VideoPort, and AudioPort parameters. And maybe you have to make sure that theRequest.Target.Typeis the right controller type.