I'm trying to use Guice to bind various processor classes where each 
processor takes a config object ( country specific ) and can operator on 
that county. 

interface Config
    {
        String getName();
    }

    interface Processor
    {
        String getName();
    }

     class Process
    {
        private final Map<String, Processor> processorMap;

        @Inject
        public Process(final Map<String, Processor> processorMap)
        {
            this.processorMap = processorMap;
        }

        String process(final String country)
        {
            return processorMap.get(country).getName();
        }
    }

class ConfigA implements Config {
}

class ConfigB implements Config {
}

     class ProcessorA implements Processor
    {

        public ProcessorA(final SomeADeps deps, final Config config) {}
} 


     class ProcessorB implements Processor
    {

        public ProcessorB(final Config config, final SomeBDeps deps) {}
} 

  class Process
    {
        private final Map<String, Processor> processorMap;

        @Inject
        public Process(final Map<String, Processor> processorMap)
        {
            this.processorMap = processorMap;
        }

        String process(final String country)
        {
            return processorMap.get(country).getName();
        }
    }


In the binding section
public class TestModule extends AbstractModule {
 protected void configure()
    {
        //All the config object are created by loading from various 
property files
        Map<String, Config> countryToConfigMap;  // This map is populated

        //I also have a property file, that says
        // country US > use ProcessorA ( with ConfigA instance 1 )
        // country UK > use ProcessorA  ( with ConfigA instance 2 )
        // country DE > use ProcessorB  ( with ConfigB instance 1 ) 
        //etc 

       //TODO: How to bind Process class ?
    } 
}

In the main class, I'm trying to do something like this:

Injector injector = Guice.createInjector(new TestModule());
Process process = injector.getInstance(Process.class);
System.out.println("Name:" + process.process("US"));


Could someone help me understand and figure out on how to go about solving 
the above design using guice ?

Thanks!

-- 
You received this message because you are subscribed to the Google Groups 
"google-guice" group.
To view this discussion on the web visit 
https://groups.google.com/d/msg/google-guice/-/gS4dCrnJ_kkJ.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/google-guice?hl=en.

Reply via email to