0

I have written a class like following:

public class MyClass {
@Inject
@Named("MyMap1")
private Map<String, IEmployeeManager> myMap1;

@Inject
@Named("MyMap2")
private Map<String, ICustomerManager> myMap2;

@Inject
private ConfigManager configManager;

...
}

This class has no constructor. I cannot figure out how to inject depencies for this. In above code two map binders MyMap1 and MyMap2 I am constructing in module as follows:

public class ManagerConfigModule extends AbstractModule {
@Override
protected void configure() {

    MapBinder<String, IEmployeeManager> myMap1 = MapBinder.newMapBinder(binder(), String.class,
            EmployeeManager.class, Names.named("MyMap1"));

    myMap1.addBinding(SDEObj.class.getName()).to(SDManager.class)
            .asEagerSingleton();
    myMap1.addBinding(ASObj.class.getName()).to(VPManager.class)
            .asEagerSingleton();

    MapBinder<String, ICustomerManager> myMap2 = MapBinder.newMapBinder(binder(), String.class,
            CustomerManager.class, Names.named("MyMap2"));
    ...
 }
Joy
  • 4,197
  • 14
  • 61
  • 131
  • You can add a constructor? And did you start writing a test? Do the siilar questinos like https://stackoverflow.com/questions/5633915/guice-injector-in-junit-tests not solve your problem? – tkruse Jan 15 '18 at 06:14
  • Here I cannot add a constructor I think. – Joy Jan 15 '18 at 06:50
  • Also related: https://stackoverflow.com/questions/4238919/inject-generic-implementation-using-guice – tkruse Jan 15 '18 at 07:16

0 Answers0