Off the cuff, you could probably do this with PrivateModules:

public class DatabaseOneModule extends PrivateModule {
  @Override protected void configure() {
     Names.bindProperties(binder(), loadProperties("*database_one.properties
*" ));
   Key<DataSource> dataSourceKey = Key.get(Datasource.class, DbOne.class);
   bind(dataSourceKey)
        .toProvider(MySQLDataSourceProvider.class)
         .in(Singleton.class); // prefer Singleton.class over
Scopes.SINGLETON
   expose(dataSourceKey);
  }
}

...and you'd have something almost identical for DatabaseTwoModule (in fact,
you could probably parameterize a generic module to accept the file name and
the annotation you want, but that's not the most salient point here).

Then you install DatabaseOneModule and DatabaseTwoModule and I suspect you
will get what you're looking for.

-Fred

On Sat, Jan 29, 2011 at 12:57 PM, Evan Ruff <[email protected]> wrote:

> Guy guys,
>
> Guice newbie here. I'm trying to migrate my DAO Factory Pattern to a Guice
> provider framework. The issue I'm having is figuring out how to create data
> sources that point to various databases, all in the same module. For a
> single database, I'm golden, everything is working great; however, I'm not
> sure how to proceed.
>
> I've got my ProductionDatabaseModule (AbstractModule) that does that does:
>
>     protected void configure() {
>         Names.bindProperties(binder(), loadProperties("*
> database_one.properties*" ));
>         bind(DataSource.class).annotatedWith( *@DBOne *
> ).toProvider(MySQLDataSourceProvider.class).in(Scopes.SINGLETON);
>     }
>
> What I'd like to do, is follow it up with something like this:
>
> Names.bindProperties(binder(), loadProperties("*database_two.properties*"
> ));
> bind(DataSource.class).annotatedWith( *@DBTwo *
> ).toProvider(MySQLDataSourceProvider.class).in(Scopes.SINGLETON);
>
> But I don't understand how to make my second binding hook up to the second
> properties file without overwriting the first. Any recommendation on how to
> handle this?
>
> Thanks for helping out the new guy!
>
> E
>
> --
> 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.

Reply via email to