Thanks Oliver.
but i don't understand how assistedinject can help me.
can you help me fix this example code.
/* Main */
public class Main {
public static class MainModule extends AbstractModule {
@Override protected void configure() {
bind(RemoteServiceX.class).to(RemoteServiceXImpl.class);
bind(RemoteServiceY.class).to(RemoteServiceYImpl.class);
}
}
public static void main(String[] args) {
Injector inejector = Guice.createInjector(new MainModule());
Test test = inejector.getInstance(Test.class);
Command command = test.processRequest("commandX");
command.execute();
}
}
public class Test {
public Command processRequest(String commandName) {
if( commandName.equals("commandX") )
return new CommandX(?); //HERE IS THE PROBLEM
else if ( commandName.equals("commandX") )
return new CommandY(?); //HERE IS THE PROBLEM
return null;
}
}
/* Command */
public interface Command {
void execute();
}
public class CommandX implements Command {
private RemoteServiceX service;
private String runtimeParameter;
@Inject public CommandX(RemoteServiceX service, String
runtimeParameter) {
this.service = service;
this.runtimeParameter = runtimeParameter;
}
@Override public void execute() { /*TODO: implements this method*/ }
}
public class CommandY implements Command{
private RemoteServiceX service;
private String runtimeParameter;
@Inject public CommandY(RemoteServiceX service, String
runtimeParameter) {
this.service = service;
this.runtimeParameter = runtimeParameter;
}
@Override public void execute() { }
}
/* Services */
public interface RemoteServiceX {
public void specificMethod1OfServiceX();
public void specificMethod2OfServiceX();
}
public class RemoteServiceXImpl implements RemoteServiceX {
@Override public void specificMethod1OfServiceX() {/*TODO: implements
this method*/}
@Override public void specificMethod2OfServiceX() {/*TODO: implements
this method*/}
}
public interface RemoteServiceY {
public void specificMethod1OfServiceY();
public void specificMethod2OfServiceY();
}
public class RemoteServiceYImpl implements RemoteServiceY {
@Override public void specificMethod1OfServiceY() {/*TODO: implements
this method*/}
@Override public void specificMethod2OfServiceY() {/*TODO: implements
this method*/}
> 2009/4/21 ale <
ale.sch...@gmail.com>