AssistedInject does something similar. See: http://code.google.com/p/google-guice/wiki/AssistedInject & the FactoryModuleBuilder javaodc @ http://google-guice.googlecode.com/svn/trunk/javadoc/com/google/inject/assistedinject/FactoryModuleBuilder.html . Rather than changing the response based on the input, though, there's a different factory methods that return the different objects. Changing the response based on the input will necessarily require a hand-written factory (but that factory can still use Guice-injected objects, easing some of the pain).
sam On Wed, Dec 28, 2011 at 3:47 PM, egolan <[email protected]> wrote: > Hi, > Our whole project uses hand-written DI and I really want to switch to > Guice. > Here's something we have and I would like to understand how it's done > with Guice. > > we have a factory method, that based on an input string, returns a > specific implementation of an Abstract Factory: > > public class TypeFactoryCreator { > public static AggregationStrategyHolder > createStrategyHolder(IConfiguration configuration, Date toDate) { > > switch (enum based on a string) { > ... > } > > AggregationStrategyHolder has two members (strategy and abstract > factory): > public class AggregationStrategyHolder { > private final AggregationStrategy aggregationStrategy; > private final AggregationFactory aggregationFactory; > ... > } > > So, the factory method builds the strategy and AggregationFactory > based on input string. > AggregationFactory is an Abstract Factory design pattern. > > > So I think that my question should be, how to bind different classes > according to runtime input? > > Was I clear ? :) > > Thanks > > Eyal > > -- > You received this message because you are subscribed to the Google Groups > "google-guice" group. > 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. > > -- You received this message because you are subscribed to the Google Groups "google-guice" group. 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.
