I have the following code:
class Controller
{
public Controller(Listener audioListener,
Listener videoListener)
{}
}
class Listener
{
public Listener(int port)
{
Console.WriteLine(port);
}
}
Now I need that the Listener is resolved one time with audioPort and the other with videoPort.
var audioPort = 1330;
var videoPort = 1331;
var controller = kernel.Get<Controller>(); // should print 1330 and 1331
So far I’ve done this when binding with WithConstructorArgument that takes a callback. I was wondering if I can set the callback when actually resolving the type?
I did a little research, and obviously the problem is different.
The arguments are run-time dependencies. And the way I wanted to do this, is related to the service locator pattern, which is complicated in testing.
A better way of using run-time arguments is explained here.