why not have expose() simply do the bind if not already bound? On Wed, Feb 4, 2009 at 5:43 PM, Sam Berlin <[email protected]> wrote:
> > Is it possible for PrivateModules to override the bind(..) method to > return a sub-interface that adds additional methods, eventually > leading towards being able to say > > bind(A.class).to(Y.class).expose(); > > Sam > > > On Wed, Feb 4, 2009 at 1:25 AM, [email protected] <[email protected]> > wrote: > > > > On Feb 3, 1:48 pm, Leigh Klotz <[email protected]> wrote: > >> I realize you said that it was just mail-buffer code, but it brings up > >> a question for me. > >> > >> The alternating lines of bind and expose in Private Modules have > >> always struck me as being clunky. > >> > >> Your example below with expose(BaseDao.class).annotatedWith > >> (Gui.class).to(...) looks cleaner, but I don't see it working, at > >> least not in the last snapshot (20081123). > >> > >> I checked <http://google-guice.googlecode.com/svn/trunk/latest-javadoc/ > >> com/google/inject/PrivateModule.html> and don't see a hint of this > >> rather reasonable looking usage there either. > > > > There's some small problems with the integrated 'bindAndExpose()' > > syntax... > > > > You still need a regular expose() syntax, to cover the case when > > you're exposing something that comes from a module that you've > > installed. > > install(new FooModule()); > > expose(Foo.class); > > > > Having both bindAndExpose() and expose() can get confusing, especially > > for concrete types with no 'to()' clause; ie: > > bindAndExpose(Foo.class); > > > > It's less explicit about what's being exposed. The expose() method > > exposes the key, but not the target. With an integrated syntax, it's > > not as obvious that 'Foo' is exposed, but not 'FooImpl' in this > > example: > > bind(Foo.class).to(FooImpl.class); > > expose(Foo.class); > > vs. > > bindAndExpose(Foo.class).to(FooImpl.class); > > > > If it proves to be a big problem, it's fairly straightforward to add a > > utility method that implements bindAndExpose() on top of bind() and > > expose(). > > > > Cheers, > > Jesse > > > > > > > > > > > > > --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
