Can one module installed twice?

1,604 views
Skip to first unread message

Hanlu Chen

unread,
Sep 8, 2014, 9:09:21 PM9/8/14
to google...@googlegroups.com
There are four modules A, B, C, D. 
Their dependency is like graph below
   A   D
  |   \ /
  |   B
  |  /
  C
Could I install C & B in A and then install C in B again?
The experiment would just work, but I failed to find any doc supporting this. 
Thanks.

Thomas Broyer

unread,
Sep 9, 2014, 4:55:31 AM9/9/14
to google...@googlegroups.com
IIRC, the modules need to compare equal (i.e. C.equals(C) == true), otherwise C would be installed twice and lead to duplicate bindings.
Not sure there's any doc, but I remember fixing something similar in GIN (Guice for/in GWT) a while ago.

Tavian Barnes

unread,
Sep 11, 2014, 5:31:56 PM9/11/14
to google...@googlegroups.com
This is true, but brittle to rely on (anything using the SPI like Modules.override() will break equality).  It's better to rely on the fact that equivalent bindings get de-duplicated.

The one caveat is that to get @Provides methods to de-duplicate, the modules have to compare equal anyway.

Andrés Testi

unread,
Sep 23, 2014, 10:03:33 AM9/23/14
to google...@googlegroups.com
You can check the ServletModule.configure() method to see a pattern to deal with twice installations: https://github.com/google/guice/blob/master/extensions/servlet/src/com/google/inject/servlet/ServletModule.java#L52
Reply all
Reply to author
Forward
0 new messages