Here is a fully contained example, you don’t even need a provider. Launch
it and you'll get "Value: 32".
@Singletonclass Arg {
@Parameter(names = "-long")
public long l;
}
public class Main {
@Inject
private Arg arg;
public static void main(String[] args) throws Exception {
Injector inj = Guice.createInjector();
inj.getInstance(Main.class).f();
inj.getInstance(B.class).showInjection();
}
public void f() {
new JCommander(arg).parse("-long", "32");
}
}
class B {
@Inject
private Arg arg;
public void showInjection() {
System.out.println("Value: " + arg.l);
}
}
--
Cédric
On Fri, Nov 15, 2013 at 9:19 PM, Maatary Okouya <[email protected]>wrote:
> All the example i see do the configuration within one point the main. What
> about if one need to inject some dependence at different point in the code.
> Is there a way to retreive the same injector, is it a singleton, like for
> loggers for instance etc... ?
>
> --
> You received this message because you are subscribed to the Google Groups
> "google-guice" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to [email protected].
> To post to this group, send email to [email protected].
> Visit this group at http://groups.google.com/group/google-guice.
> For more options, visit https://groups.google.com/groups/opt_out.
>
--
You received this message because you are subscribed to the Google Groups
"google-guice" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/google-guice.
For more options, visit https://groups.google.com/groups/opt_out.