You have to put both of them in PrivateModules, and export the things you
need.
On Wednesday, 23 March 2016 13:16:51 UTC-4, Chris Kessel wrote:
>
> I must be doing something wrong then. I'm using Dropwizard, which does
> this behind the scenes:
> injector =
> injectorFactory.create(this.stage,ImmutableList.copyOf(this.modules));
>
> I'm passing in that list of modules.
>
> This works:
> Arrays.asList(myModule, airlineModule);
>
> This fails:
> Arrays.asList(
> myModule,
> new PrivateModule() {
> protected void configure() {
> install(airlinesModule);
> }
> });
>
> It fails with:
>
> 1) Unable to create binding for com.kessel.airlines.AirlineCache. It was
> already configured on one or more child injectors or private modules
> bound at com.kessel.airlines.AirlineModule.provideAirlineCache() (via
> modules: com.kessel.MyMain$1 -> com.kessel.airlines.AirlineModule)
> If it was in a PrivateModule, did you forget to expose the binding?
>
> However, the AirlineCache is provided in the AirlineModule. Why is
> wrapping it in a PrivateModule causing this failure?
> @Provides
> @Singleton
> public AirlineCache provideAirlineCache() {
> ...
> }
>
> On Tuesday, March 22, 2016 at 4:53:28 PM UTC-7, scl wrote:
>>
>> Private modules is the way to go.
>> A binding in a private module can see all other bindings in the same
>> private module and all bindings of all non private modules.
>>
>>
>>
>> On 22.03.2016 21:58, Chris Kessel wrote:
>>
>> I'm adding two Guice modules, but they both have an @Provides for the
>> same item. They're both 3rd party modules, so I can't modify the code. How
>> do I prevent the collision? I really need each module to use it's own
>> provided version. I guess the equivalent of each living within it's own
>> "scope" where it's provided items aren't visible to the other modules.
>>
>> Guice.createInjector(Stage.DEVELOPMENT, Arrays.asList(moduleA, moduleB));
>>
>> I've tried wrapping them in a PrivateModule, but then they don't seem to
>> even see their own @Provides...maybe I'm not understanding how to configure
>> a PrivateModule? I'll actually want expose one specific class from each
>> module to to my module that I'm developing, but my first step was trying to
>> get these two other modules to coexist.
>>
>> The injector supports creation with multiple modules and it seems like
>> provider collision would happen now and then, so presumably there's some
>> way to deal with that I'm not groking...
>>
>> Thanks,
>> Chris
>>
>> --
>> 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 https://groups.google.com/group/google-guice.
>> To view this discussion on the web visit
>> <https://groups.google.com/d/msgid/google-guice/26e2e40f-3b26-4ec5-bd20-1c3a2f67fd1e%40googlegroups.com?utm_medium=email&utm_source=footer>
>> https://groups.google.com/d/msgid/google-guice/26e2e40f-3b26-4ec5-bd20-1c3a2f67fd1e%40googlegroups.com
>> .
>> 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 https://groups.google.com/group/google-guice.
To view this discussion on the web visit
https://groups.google.com/d/msgid/google-guice/bc7c374e-333c-4655-8463-647591e93760%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.