Hi,

I have a peculiar use case:
- I have 3 libraries, Core, Sub and OtherSub
- Sub and OtherSub do not know anything about each other, but they know the 
existence of Core
- Sub and OtherSub override the same functionality in Core
- In a project, I want to combine Sub and OtherSub.

It does not work, but here is how I wanted to implement this pattern with 
Guice:
- in the Core library:
    o bind(A.class).to(ACore.class)
    o class ACore implements A {
        @Override public String a() { "a"; }
    }
- in the Sub library:
    o bind(A.class).to(ASub.class)
    o class ASub implements A {
        private final A parent; // instance of ACore or AOtherSub
        @Inject ASub(A parent) { this.a = parent; }
        @Override public String a() { parent.a() + " overriden"; }
    }
- in the OtherSub library:
    o bind(A.class).to(AOtherSub.class)
    o class AOtherSub implements A {
        private final A parent; // instance of ACore or ASub
        @Inject ASub(A parent) { this.a = parent; }
        @Override public String a() { parent.a() + " !"; }
    }

then in the projet using this set of libraries, I would have been able to 
do:
- Guice.createInjector(Modules.override(new ModuleCore()).with(new 
AOtherSub())).getInstance(A.class).a() // returns "a !"
- Guice.createInjector(Modules.override(Modules.override(new 
ModuleCore()).with(new ASub())).with(new 
AOtherSub())).getInstance(A.class).a() // returns "a overriden !"
- Guice.createInjector(Modules.override(Modules.override(new 
ModuleCore()).with(new AOtherSub())).with(new 
ASub())).getInstance(A.class).a() // returns "a ! overriden"

In this implementation, this throws a StackOverflowError because in ASub or 
in AOtherSub the instance creation falls in an infinite loop.

Is there a way of doing something like that with Guice ?
Else do you have any insight on how I should implement this use case ?

Cheers,
Aurélien

-- 
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/5d2d4bdc-f52e-4143-82dd-5bc5865a7668%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to