What you have is a design problem.  If A needs B to exist, and B needs A to 
exist, then either

 - There is some other implicit object that provides data to both A and B, 
or
 - You really have one logical class, and your implementation is trying to 
pretend it's two

The most straightforward way to resolve this is *don't use Guice to 
construct these.*  I.e. A constructs a B and passes "this" to it and stores 
it as a field.  Done.

Or if you want to use Guice to construct it (and arguably a better design), 
have

@Inject
A (AandBData data) {...}
...
@Inject
B (AandBData data) {...}

-Tim
On Friday, December 19, 2014 1:31:31 PM UTC-5, [email protected] wrote:
>
> Hello all.
>
> Lets say I have:
>
> class A {
> //...
> }
>
> class B {
>     A getA() {
>         // Building a A using B attributes
>     }
> //...
> }
>
> I'd love to write:
>
> class B {
>     private final a;
>
>     @Inject
>     private B(A a) {
>         this.a = a;
>     }
> //...
> }
>
> But, since the building of the A instance relies on some data from B, I 
> can not.
> Typical exemple would be two classes mapping two SQL tables, where getA() 
> is following a foreign key.
>
> Is there a way Guice can be used around here? (Factory that uses "this", 
> something like that)
> Perhaps is it a silly question, and I should do my "new" thing as I would 
> if Guice wasn't around; but it is, so I'm trying to find the proper answer 
> here.
>
>
> Adrien.
>

-- 
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/994f5a1e-76ed-4f4d-9dd3-08bc69cd3164%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to