Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>As others have already answered, you can simply use <code>@Inject Injector</code> because Guice defines the binding itself.</p> <p>Normally you only need one <code>Injector</code> in your app, and a static variable is an even easier way to store and access a singleton than injecting it. In our web app, we use <a href="http://code.google.com/p/stripes-guicer/" rel="nofollow noreferrer">stripes-guicer</a> and get the <code>Injector</code> from its static method <code>GuiceInjectorFactory.getInjector()</code> when we need it (in our Hibernate interceptor, for example).</p> <p>I'm a little baffled by the advice that "you shouldn't use Injector directly." How else would I get an instance injected except by calling <code>injector.getInstance()</code> or <code>injector.injectMembers()</code>? There is no way. Yes, you can define Provider methods, but they will never be called unless somewhere, something uses an Injector. Yes, there are modules that use the <code>Injector</code> for you like the <a href="https://github.com/google/guice/wiki/ServletModule" rel="nofollow noreferrer">ServletModule</a>; you have to create the <code>Injector</code> yourself, but you can leave it to the <code>ServletModule</code> after that.</p> <p>So in some circumstances, you can avoid using the <code>Injector</code> directly, but that doesn't mean you "shouldn't" use it. If you're using Guice alone without any optional modules, then you "should" be using an <code>Injector</code> all over the place because there's no other way to trigger injection. (I think developers who spend all day writing code inside frameworks sometimes forget that some people actually instantiate their own objects.)</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload