Injecting a dependency into Guice Module
<p>I have a module that acquires and holds an API token (simplified): </p>

<pre><code>@Singleton
public class KeyHolderModule extends AbstractModule {
    // This doesn't seem to be injected
    private @Inject TokenConnector connector;
    private DateTime keyLastRefreshed;
    private String key;
    private Credentials creds = config.getCreds();

    @Override protected void configure() {
        this.key = connector.getToken(creds);
        this.keyLastRefreshed = DateTime.now();
    }

    @Provides @Named("apiKey") public String getKey() {
        // logic to check key last refreshed and handle generating a new one
        return this.key;
    }
}
</code></pre>

<p>I get a null pointer error on the line where I try to access the connector (<code>this.key = connector.getToken(creds);</code>), so the connector is obviously not getting wired up correctly. </p>

<p>I've tried creating a constructor and using @Inject there, but I'm manually adding these modules via <code>new</code> to a list in my app bootstrap class, so that's sort of out. </p>

<p>Obviously I'm missing something here -- I could probably just <code>new</code> up a <code>TokenConnector</code> in this case since it doesn't have any dependencies itself, but that wouldn't fix my fundamental failure to grasp what's happening here. So if you want to see (simplified) other pieces of code, or less simplified pieces of this code, let me know.</p>