I've found that despite a few drawbacks, private modules are the way to go. I seem to end up with complicated object graphs and have had some serious issues (customer affecting) when something is used that was not intentionally to be around for public consumption0 (like a single threaded ScheduledExecutorService that gets locked up by an unexpected user).
The only issue I really run into between the differences is with type listeners, they only receive exposed / public objects. So I've always had to bind my listeners inside of private modules. (Note: exposed objects get listened to more than once which is ok in my use case). This hasn't been a huge drawback, and is worth the guarantee of safety as a code base (and its development team) grow. On Thu, Jun 25, 2015 at 10:11 AM Tavian Barnes <[email protected]> wrote: > PrivateModules are conceptually more complicated because they necessarily > involve a hierarchy of injectors instead of just one. As well, you can't > expose() everything from a PrivateModule, for example AOP interceptors. So > personally I'd recommend only using PrivateModules when necessary. > > Usually I just hide implementation types by making them package-private. > That way no one else can get at them even if they're exposed in the root > injector. > > > On Thursday, 25 June 2015 09:04:58 UTC-4, KimJohn Quinn wrote: >> >> I am wondering what best practices people use when applying private >> modules in a large system. >> >> We currently use a conventional approach of all modules are not private >> unless explicitly required. We are considering, as a pattern, making each >> major module bind its components privately and only expose its public >> interfaces. >> >> Are there any pros/cons of relying on private modules heavily? >> >> >> -- > You received this message because you are subscribed to the Google Groups > "google-guice" group. > To unsubscribe from this group and stop receiving emails from it, send an > email to [email protected]. > To post to this group, send email to [email protected]. > Visit this group at http://groups.google.com/group/google-guice. > To view this discussion on the web visit > https://groups.google.com/d/msgid/google-guice/32b41b9a-1af0-4177-bb5f-ffd26d591c79%40googlegroups.com > <https://groups.google.com/d/msgid/google-guice/32b41b9a-1af0-4177-bb5f-ffd26d591c79%40googlegroups.com?utm_medium=email&utm_source=footer> > . > For more options, visit https://groups.google.com/d/optout. > -- You received this message because you are subscribed to the Google Groups "google-guice" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To post to this group, send email to [email protected]. Visit this group at http://groups.google.com/group/google-guice. To view this discussion on the web visit https://groups.google.com/d/msgid/google-guice/CAHNex9_8KnSH0gLpUBK1GmexEE11WXyg5mr%2BthrURqY5rCHyyA%40mail.gmail.com. For more options, visit https://groups.google.com/d/optout.
