The thing you are looking for is called assisted injection.
https://github.com/google/guice/wiki/AssistedInject

But often when you need to pass runtime values to an object created with guice. 
The object is a mix between a data structure and a business object. Try to 
separate them and the assisted injection becomes unnecessarry.


Am 19. Dezember 2014 19:31:31 MEZ, schrieb adrien.barr...@live.fr:
>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 google-guice+unsubscr...@googlegroups.com.
>To post to this group, send email to google-guice@googlegroups.com.
>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/061aeb37-8183-45f5-8d17-227ae8604110%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 google-guice+unsubscr...@googlegroups.com.
To post to this group, send email to google-guice@googlegroups.com.
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/1E8E15E2-8E31-43D7-AA4B-86DA4257B69F%40gmx.ch.
For more options, visit https://groups.google.com/d/optout.

Reply via email to