Thanks for this Robbie. I'll have to see how Guice2 works with my testng stuff and I'll give this a try.
On Wed, Jan 14, 2009 at 5:50 PM, Robbie Vanbrabant < [email protected]> wrote: > > > On Wed, Jan 14, 2009 at 10:17 PM, Rick <[email protected]> wrote: > >> >> >> On Wed, Jan 14, 2009 at 3:23 PM, Robbie Vanbrabant < >> [email protected]> wrote: >> >>> I think the more elegant solution (Guice 2.0) would be to use private >>> modules: >>> >>> http://google-guice.googlecode.com/svn/trunk/latest-javadoc/com/google/inject/PrivateModule.html >>> >>> Avoiding work in modules is almost always a good thing, explained here: >>> >>> http://code.google.com/p/google-guice/wiki/ModulesShouldBeFastAndSideEffectFree >>> >>> Hope this helps >>> Robbie >>> >>> >> >> I'm confused how I would go about doing this not in a module (I'd go with >> guice2 but I'm worried about the testing stuff and not sure it'll work with >> 2. I'm using the mycila stuff with TestNG.) My module looks like: >> >> @Override >> protected void configure() { >> >> SqlMapClient guiSqlClient = >> DaoUtil.loadSqlMapClient("sqlMapConfig-gui.xml"); >> SqlMapClient ndaSqlClient = >> DaoUtil.loadSqlMapClient("sqlMapConfig-nda.xml"); >> >> >> bind(SqlMapClient.class).annotatedWith(Names.named("GUI")).toInstance(guiSqlClient); >> >> bind(SqlMapClient.class).annotatedWith(Names.named("NDA")).toInstance(ndaSqlClient); >> >> How would I do this outside of my module? >> > > Rough Guice 2.0 example (quickly coded in gmail): > > Usage: > new DaoModule() { > @Override > protected void customBindings() { > expose(BaseDao.class).annotatedWith(Gui.class).to(...); > bindConstant().annotatedWith(Names.named("xml")).to(xml); > } > } > > Implementation: > abstract class DaoModule extends PrivateModule { > void configure() { > customBindings(); > } > > @Provides > public SqlMapClient provideSqlMapClient(@Named("xml") String xml) { > return DaoUtil.loadSqlMapClient(xml); > } > > abstract void customBindings(); > } > > You could also do something similar with Guice 1.0, but it will require > more code because you need to use more binding annotations. > > Hope this helps, > Robbie > > > > -- Rick --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
