title: Guice: How to change injection on runtime based on a (dynamic web property)
body: <p>The following is an approximation of the problem I'm facing.</p>
  
  <p>Think we have a password validator with some rules.</p>
  
  <pre><code>public interface RuleChecker{
  
      //Checks for a password strenght, returns 10
      //for strong or 0 for soft password.
      int check(String pass);
  }
  </code></pre>
  
  <p>And then we have several implementations, our service will only accept the password if it is over 8 score.</p>
  
  <pre><code>public class NoCheck implements RuleChecker {
      public int check(String pass){return 10;}
  }
  
  public class LengthCheck implements RuleChecker{
      ...
  }
  public class AlphanumericCheck implements RuleChecker{
      ...
  }
  public class AlphaAndLenghtCheckAdapter implements RuleChecker{
      ...
  }
  </code></pre>
  
  <p>But for testing purposes, we want to implement a webservice within the application where we can "admin" those rules, and select which ones to have.</p>
  
  <pre><code>public class PasswordCheckService{
  
       private RuleChecker checker;
  
       @Inject
       public PasswordCheckService(final RuleChecker checker){
           this.checker = checker;
       }
  
       public boolean checkPassword(String password){
           return checker.check(password) &gt; 8;
       }
  }
  </code></pre>
  
  <p>So, is there any way in Guice, to change at runtime, the injection a service has?</p>
  
  <p>Example:</p>
  
  <p>We started the application and by default LengthCheck is selected and injected on the application, at the website we select the NoCheck checkbox and save options, which is stored into the database, can I configure Guice to automatically change the bean the service had injected before? so from now and on there will be no checks on new passwords?</p>
  
  <p>--</p>
  
  <p>As for now, I have found those topics </p>
  
  <p><a href="https://stackoverflow.com/questions/7651980/google-guice-and-varying-injections-at-runtime">Google Guice and varying injections at runtime</a>
  But i dont know if that kind of providers fits my problem.</p>
  
  <p><a href="https://stackoverflow.com/questions/7641565/guice-runtime-dependency-parameters-reinjection">Guice runtime dependency parameters reinjection</a>
  That nice question is talking something similar, but not what I'm looking form.</p>
  
  <p><a href="https://stackoverflow.com/questions/7663618/guice-runtime-injection-binding-at-command-line">guice: runtime injection/binding at command line</a>
  This is the closest to my problem but he only does on starting "runtime" and does not change it over the time.</p>
  
  <p>Any helps?</p>
  
  <p>Thank you!</p>
  
  <p>Using the tip of the first comment I implemented this POC but still does not works, if you change select another button the service bean is not updated.
  <a href="https://bitbucket.org/ramonboza/guicedynamicconfig" rel="nofollow noreferrer">https://bitbucket.org/ramonboza/guicedynamicconfig</a></p>