I think largely, the issue with conditional bindings in some cases is that it requires the inclusion of the superset of compile-time dependencies within an application. There is also the practical matter of wanting to know exactly how an application is configured within production; using conditional bindings introduces the risk of being able to oversee a mistake of flag value and e.g., use a NoOp<something> when you really want a Real<something>. Generally speaking it's not the end of the world if you use conditional bindings, but you should recognize the downsides before doing so.
On Sun, Apr 4, 2010 at 1:23 PM, rod <[email protected]> wrote: > I don't think it's a really bad solution, I just read this page - > http://code.google.com/p/google-guice/wiki/AvoidConditionalLogicInModules - > and wanted to check there wasn't a better way to do this. > > Cheers, > rod. > > > On 4 April 2010 14:33, Max Bowsher <[email protected]> wrote: > >> rod wrote: >> > Hi, >> > >> > I'm sure this question must have been asked a million times but I >> > can't find the answer... >> > >> > In my application the user can provide command line flags for various >> > options, one being the type of database to use. So I have a bunch of >> > implementations of my Database interface, and at the moment on startup >> > I do... >> > >> > if ( dbType.equals("mysql") ) { >> > // create mysql implementation >> > } >> > else if ( dbType.equals("other..") ) { >> > // ... >> > } >> > else { >> > // some other implementation... >> > } >> > >> > The database class is then injected into components when needed. How >> > is this handled with Guice? The only way I can see is to move this >> > logic to my module like this... >> > >> > if ( dbType.equals("mysql") ) { >> > bind( Database.class ).to( MySQLDatabase.class ); >> > } >> > >> > Is there a better way? >> >> What's wrong with the method that you describe above that you seek to >> improve upon? >> >> Max. >> >> > > > -- > "I backed my car into a cop car the other day. But he just drove on, > sometimes life's ok." > > -- > 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]<google-guice%[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.
