title: Constructor parameter injection using guice
body: <p>This is a slightly different question from the other answered questions about constructor parameter (or at least that's what I think so, course I may be wrong). So am using a MapBinder to store a bunch of implementations and then pick one during runtime based of some criteria. Here is some code:</p>
  
  <pre><code>public interface MessageService {
    void send();
  }
  
  public class FacebookMessageService implements MessageService {
    private final String name;
  
    @Inject
    public FacebookMessageService(String name) {
      this.name = name;
    }
  
    public void send() {
      System.out.println("Sending message via facebook service to " + name);
    }
  }
  
  public class MessageModule extends AbstractModule {
    @Override
    protected void configure() {
      MapBinder&lt;String, MessageService&gt; mapBinder = MapBinder.newMapBinder&lt;.....&gt;
      mapBinder.addBinding("facebook").to(FacebookMessageService.class);
    }
  }
  
  public class MessageClient {
    @Inject
    Map&lt;String, MessageService&gt; map; //Mapbinder being injected
  
    public void callSender() {
      Injector injector = Guice.createInjector(new MessageModule());
      injector.injectMembers(this);
  
      MessageService service = map.get("facebook");
      service.send();
    }
  }
  </code></pre>
  
  <p>I am unable to figure out how to get the <code>FacebookMessageService</code> with the <code>name</code> parameter? If I use <code>AssistedInject</code> with a <code>Factory</code> then I am not able to figure out how to inject the implementation into the <code>MapBinder</code>.</p>