title: Inject Configuration in Guice AbstractModule in Dropwizard Application
body: <p>I am working on an application developed using Guice and Dropwizard, where we are creating different bundles like guice bundle, migrations bundle, etc. and adding them to bootstrap in initialize() method.</p>
  
  <p>I am trying to inject Configuration object in MyModule class, but unable to do so.</p>
  
  <p>Following is the code for Application class:</p>
  
  <pre><code>public class MyApplication extends Application&lt;MyConfiguration&gt; {
  
      public static void main(String args[]) throws Exception {
          new MyApplication().run(args);
      }
  
      private GuiceBundle&lt;MyConfiguration&gt; guiceBundle = GuiceBundle.&lt;MyConfiguration&gt; newBuilder()
          .addModule(new MyModule()).enableAutoConfig(getClass().getPackage().getName())
          .setConfigClass(MyConfiguration.class).build(Stage.DEVELOPMENT);
  
      @Override
      public void initialize(Bootstrap&lt;MyConfiguration&gt; bootstrap) {
          bootstrap.addBundle(guiceBundle);
      }
  
      @Override
      public void run(MyConfiguration configuration, Environment environment) throws Exception {
          ...
      }
  }
  </code></pre>
  
  <p>Below is Module class which extends AbstractModule:</p>
  
  <pre><code>public class MyModule extends AbstractModule {
  
      @Override
      protected void configure() {
  
      }
  }
  </code></pre>
  
  <p>With this approach, I am finding it hard to inject Configuration object in Module class, as Configuration object is not available in initialize() method, but is available in run() method.</p>
  
  <p>Is there any alternative way to do this?</p>
  
  <p>Note: I am aware of another way where you can create an object of Module class in run() method for creating an injector (with configuration and environment object passed as parameters in the constructor of MyModule class). But this would require me to register all Managed objects and all resources in run() method. I want to avoid doing that.</p>