Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>The <code>Modules.override()</code> is not working in <code>Stage.PRODUCTION</code>. You should use <code>PrivateModule</code> where the binding is valid/visible only inside private module, so you can bind different implementation classes to the same interface. Then you can install the Private module to the parent Module, but you have to explicitly <code>expose()</code> all binding you want to make visible for other modules. </p> <p><a href="https://google.github.io/guice/api-docs/latest/javadoc/index.html?com/google/inject/PrivateModule.html" rel="nofollow noreferrer">Guice - Private Modules</a></p> <p>Lets say:</p> <p><strong>DatabaseSearchModule.java</strong> (extends PrivateModule)</p> <pre><code>bind(PlaceSearch.class).annotatedWith(Names.named("dbSearch")).to(HibernatePlaceSearch.class); bind(PersonSearch.class).to(HibernatePersonSearch.class); expose(PlaceSearch.class).annotatedWith(Names.named("dbSearch")); </code></pre> <p><strong>EleasticSearchModule.java</strong> (extends PrivateModule)</p> <pre><code>bind(PersonSearch.class).annotatedWith(Names.named("elastic")).to(PersonElasticSearch.class); expose(PersonSearch.class).annotatedWith(Names.named("elastic")); </code></pre> <p>Well then you can install it in some Parent abstract or servlet module</p> <p><strong>MainModule.java</strong></p> <pre><code>install(new DatabaseSearchModule()); install(new EleasticSearchModule()); bind(OtherClass.class); </code></pre> <p><strong>OtherClass.java</strong></p> <pre><code>@Inject @Named("elastic") private PlaceSearch elasticSearch; @Inject @Named("dbSearch") private PlaceSearch dbSearch; </code></pre> <p>You can use <code>Named</code> annotation or you can create very elegant own binding <a href="http://code.google.com/p/google-guice/wiki/BindingAnnotations" rel="nofollow noreferrer">Annotation</a>.</p>
 

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