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? I assume I'd have to bind the two instances of SqlMapClient class to an annotation in the module, but I can't make a new instance of SqlMapClient since SqlMapClient is the 3rd party class and is loaded with a 3rd party builder that you see in the the following (which is in the DaoUtil helper used above): Reader reader = Resources.getResourceAsReader("some config file"); SqlMapClient sqlMapClient = SqlMapClientBuilder.buildSqlMapClient(reader); How would I do the binding in my module so that I could then get the instance from the injector (after its created) iin order to set the SqlMapClient it needs? --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
