Hi Leigh,

Thanks for the link, I read it through.

I used this link: http://pastie.org/453944.txt and it works for me.

The only problem I found is that my "commands" can use different
numbers of argument e.g.

@Inject
  public ConcreteCommand1(SomeService service, @Assisted String
runtime1) {

@Inject
  public ConcreteCommand1(SomeService service, @Assisted String
runtime1, @Assisted String runtime2) {

.. etc...

But I resolved that issue by creating additional class
'CommandParam' : something like command design pattern:
http://en.wikipedia.org/wiki/Command_pattern

-------------------------------------
public class CommandParam {

    private final String param1;
    private final String param2;

    public CommandParam(String param1) {
        this.param1 = param1;
        this.param2 = null;
    }

    public CommandParam(String param1, String param2) {
        this.param1 = param1;
        this.param2 = param2;
    }

    public String getParam1() {
        return param1;
    }

    public String getParam2() {
        return param2;
    }

}

------------------

and replace:

@Inject
  public ConcreteCommand1(SomeService service, @Assisted String
runtime1) {

with

@Inject
  public ConcreteCommand1(SomeService service, @Assisted CommandParam
runtime1) {


and, of course, all the other stuff accordingly.


instance.process("command1",new CommandParam("This is runtime param
for command 1"));
instance.process("command2",new CommandParam("This is runtime param
for command 2","Second param"));
instance.process("command3",new CommandParam("This should fail"));

It works for me but I'm interested if this problem (variable number of
arguments) can be resolved the other way, without introducing
additional 'CommandParam' class.

--

You received this message because you are subscribed to the Google Groups 
"google-guice" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/google-guice?hl=.


Reply via email to