This is usually a thing you don't do with dependency injection. Creating a concrete instance depending on some input is what you usually do with a factory pattern [1]. What you could do in guice is: use multibinders to bind multiple implementations of the Transformer interface [2]. You would then loop over all Transformer implementations and ask each one of them if they can handle the curve type requested in the file name. This way you have a plug-in like architecture where it is possible to add more implementations of Transformer at a later time. Be aware that guice does not guarantee an order of the bound Transformer instances. If order matters you would have to sort the Set or Map of Transformer yourself. In this approach guice does not make any decision on which implementation to use. Rather it offers you all implementation it knows and you must choose which one is appropriate. [1] http://www.oodesign.com/factory-pattern.html [2] http://code.google.com/p/google-guice/wiki/Multibindings On 04/03/2014 06:29 AM, Dale Preston
wrote:
-- You received this message because you are subscribed to the Google Groups "google-guice" group. To unsubscribe from this group and stop receiving emails from it, send an email to google-guice+unsubscr...@googlegroups.com. To post to this group, send email to google-guice@googlegroups.com. Visit this group at http://groups.google.com/group/google-guice. For more options, visit https://groups.google.com/d/optout. |
- How or where to do conditional injection Dale Preston
- Re: How or where to do conditional injection Stephan Classen