java - Accessing a Map<String, Interface-Impl> which is not configurable in root object graph in Guice -


I want to know what is the equivalent of spring usage

  @ etoWire Maps & lt; String, KeyWordExecutor & gt; KeyWordExecutors;  

From what direction I guess Guice, I only want to use the instructor only in the bootstrapping part and not anywhere else. If I want to instantaneously implement the interface based on runtime input at some level of my object graph, how should I do this?

Below is some simple code I want to get and how do I do it with spring. I think the package-scan of Spring helps me pull myself in random maps and I want to know how to do it guice.

  Interface Rule Exceptor {...} Interface Key Enhancer Exchanger {...}  

Spring based code

  Class standard router applies to mutator rules Exeter {@ Autoward Map & lt; String, Keyword Excleter & gt; KeyWordExectors; Execute @ Override Public Zero (list & lt; string & gt; rule) {int val = 0; Forex currency (string rule: rule) {string keyword = getKeyWord (rules); Val = keyWordExecutors.get (keyword). Execute (val, rule)}}} class app launcher {public static zero main (string [] args) {ApplicationContext context = new FileSystemApplicationContext ("bindings.xml"); Rule mutant rules Exeter = context.getBean ("Executable"); RuleExecutor.execute (args); }}  

GUICE bootstrap

  class app launcher {public static zero main (string [] args) {Injector = Injector = Guice.getInjector (New Rule ExeterorModule ()) Rule Persecution Rule Exeter = injector.getInstace (RuleExecutor.class); RuleExecutor.execute (args); }}  

This is what it is for. From your post, it seems that the way of spring is very easy, but there is also a big XML file in the way of spring, which is easily one step :)

In Guice, you will do something like this:

@ Override Protected Zero () {Bind (Roulette Extractor.class) .to (Standard Releases Excl. Class); // Do not forget this one :) Mapbanker MB = Mapbinder Newmapbinder (typing (), string class, keyword excl. Class); . Mb.addBinding ("foo") (FooKeyWordExecutor.class); . Mb.addBinding ("Bar") (BarKeyWordExecutor.class); // etc}

Then just do the following:

  class standard rules Exxperter implies RuleExecutor {@Insject map  

Comments

Popular posts from this blog

java - org.apache.http.ProtocolException: Target host is not specified -

java - Gradle dependencies: compile project by relative path -

ruby on rails - Object doesn't support #inspect when used with .include -