Ok, thanks for all the advice.

rod.

On 5 April 2010 00:13, Kartik Kumar <[email protected]> wrote:

> If you think you can use look up an appopriate database implementation from
> a map <String, ? extends Database>, then you can also use MapBinder. You can
> find more information from MapBinder javadocs.
>
>
> On Sun, Apr 4, 2010 at 10:31 AM, Sam Berlin <[email protected]> wrote:
>
>> You can bubble the logic up to place that installs the modules. ie., have
>> a MySqlModule, a PostgresqlModule, and a GenericDbModule and conditionally
>> insert one of those modules into the list of modules that's passed to create
>> the injector.
>>
>> Sam
>>
>>
>> On 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>
>> 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]>[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].
>> 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]<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]<google-guice%[email protected]>
> .
> For more options, visit this group at
> http://groups.google.com/group/google-guice?hl=en.
>



-- 
"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].
For more options, visit this group at 
http://groups.google.com/group/google-guice?hl=en.

Reply via email to