title: Override binding or child module in Guice
body: <p>Im writing a component using Google Guice that lives next to a web application that does not use any dependency injection tool.</p>
  
  <p>The Guice Module in the component has a few "fixed" bindings that will not change and a couple that are dynamic since they change in every request from the web application.</p>
  
  <p>The easy (and bad) way that I solved this is that everytime that the web application asks the component to do something for the first time, the component builds the new Guice Module, creates the instance and returns it to the web app:</p>
  
  <pre><code>public static X init(@NotNull final Foo perRequestObject, @NotNull final Bar perRequestObject2)
  {
      final Injector injector = Guice.createInjector(new AbstractModule()
      {
          @Override
          protected void configure()
          {
              install(new NonChanging Module());
              bind(Foo.class).toInstance(perRequestObject);
              bind(Bar.class).toInstance(perRequestObject2);
          }
      });
      return return injector.getInstance(X.class);
  }
  </code></pre>
  
  <p>I think that this is a bad approach since building the Injector per request is expensive. What I would like to have is an injector already created that I can override at runtime. I found some stuff around:</p>
  
  <p>1- Override the dynamic bindings (answer <a href="https://stackoverflow.com/a/531110/1587864">https://stackoverflow.com/a/531110/1587864</a>). This still needs to create a new injector so I would have the same problem.</p>
  
  <p>2- Implement some kind of Factory that is already binded in the Injector and has the ability to access the "dynamic" properties that come from the web application and are per request. </p>
  
  <p>I'm not sure how to implement the second one, does this concept exist in Guice?</p>
  
  <p>Thanks</p>