0

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?

Matthias
  • 15,919
  • 5
  • 39
  • 84
  • There's a Get overload thta takwes parameters (including ones set to inherit down the chain). For all this sort of thing, the best answer is to look for a related example in the tests - they're neat and compact. Let us know how you get on... (Also be sure to look at the conditional binding and realted articles in the wiki). – Ruben Bartelink Jan 02 '12 at 21:44
  • Where do these ports come from? static, configuration, unknown until the creation of the listener? And are you sure that the only difference between audio and video processing is the port? Sounds a bit strange that you can do two so different things with the same implementation. – Remo Gloor Jan 02 '12 at 22:15

1 Answers1

0

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.

Community
  • 1
  • 1
Matthias
  • 15,919
  • 5
  • 39
  • 84