Comment by ahmad.ag...@gmail.com:
@Inject methods will be called when your class is initiated. for example:
{{{
public intefrace ITest {
void printMe();
}
public class Test implements ITest {
@Override public void printMe() {
System.out.println("Test me");
}
}
public interface IBilling {}
public class Billing implements IBilling {
final ITest test;
@Inject
public Billing(ITest test) {
this.test = test;
}
@Inject
public void InjectedMethod() {
test.printMe();
}
}
public class BillingModule extends AbstractModule {
@Override
protected void configure() {
bind(ITest.class).to(Test.class);
bind(IBilling.class).to(Billing.class);
}
}
public class Tester{
public static void main(String[] args) {
Injector inj = Guice.createInjector(new BillingModule());
IBilling billing = inj.getInstance(IBilling.class);
}
}
The above code will print: Test me.
Note when the Tester::main is called, it calls the injector to create
Billing class. Billing class is called, and the injectedMethod as well.
For more information:
http://code.google.com/p/google-guice/wiki/InjectingProviders
--
You received this message because you are subscribed to the Google Groups
"google-guice-dev" group.
To post to this group, send email to google-guice-dev@googlegroups.com.
To unsubscribe from this group, send email to
google-guice-dev+unsubscr...@googlegroups.com.
For more options, visit this group at
http://groups.google.com/group/google-guice-dev?hl=en.