|
|
@Inject
private Injector injector;
--
You received this message because you are subscribed to the Google Groups "google-guice" group.
To view this discussion on the web visit https://groups.google.com/d/msg/google-guice/-/Z91EearG0MIJ.
To post to this group, send email to google...@googlegroups.com.
To unsubscribe from this group, send email to google-guice...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/google-guice?hl=en.
- Does constructor injection use reflection all the time or is there an option to switch to bytecode generation?
- Is there a way to discard/shutdown the singletons? I saw Issue-62 and this seems to have been open since 2007 !!
- How do you shutdown a module and restart it - example, when it has seen network/DB/JMS errors?
- Can multiple Injector instances be created?
- This would be useful for running multiple versions of the module in parallel
- Or at least for module-level testing, I felt the need for starting the same module with different configurations
- Why isn't there a way to get the Injector from the Guice class? After creating the Injector, I had to store a reference to it in a singleton class' static field
- This singleton-for-the-Injector kind of defeated the purpose of the whole thing. I was beginning to think that a simple Registry/Factory of my own would've accomplished many of these things
You typically shouldn't use Injector directly after the initial lookup. When you depend on types, Guice can check your dependencies up front. When you get objects directly form the Injector, you don't find out about missing deps until run time.
public static void main(String[] args) {How else do you get the injectors started and create the bound services?
/*
* Guice.createInjector() takes your Modules, and returns a new Injector
* instance. Most applications will call this method exactly once, in their
* main() method.
*/
Injector injector = Guice.createInjector(new BillingModule());
/*
* Now that we've got the injector, we can build objects.
*/
RealBillingService billingService = injector.getInstance(RealBillingService.class);
...
}
I didn't quite follow what said here:The Guice example (http://code.google.com/p/google-guice/wiki/GettingStarted) does exactly that - accessing from Injector:You typically shouldn't use Injector directly after the initial lookup. When you depend on types, Guice can check your dependencies up front. When you get objects directly form the Injector, you don't find out about missing deps until run time.
public static void main(String[] args) {How else do you get the injectors started and create the bound services?
/*
* Guice.createInjector() takes your Modules, and returns a new Injector
* instance. Most applications will call this method exactly once, in their
* main() method.
*/
Injector injector = Guice.createInjector(new BillingModule());
/*
* Now that we've got the injector, we can build objects.
*/
RealBillingService billingService = injector.getInstance(RealBillingService.class);
...
}