I would also use assisted injection
http://code.google.com/p/google-guice/wiki/AssistedInject

here a sample code:

public class Foo {

    @Inject Provider<B> bProvider;
    @Inject AFactory aFactory;

    public void someMethod() {
        B b1 = bProvider.get();
        B b2 = bProvider.get();

        A a1 = aFactory.createA(b1);
        A a2 = aFactory.createA(b1);
        A a3 = aFactory.createA(b2);

        // more code

    }
}

public class A {
   
    @AssistedInject
    public A(@Assisted B b)
}


On 08/16/2013 05:16 PM, Nate Bauernfeind wrote:

The pattern that seems to make the most sense to me is to use assisted injection to create your a's (if they take more than just a b) and then you can add Named annotations to each b binding. Our create a custom annotation, which is my preference since ide's track usage.

On Aug 16, 2013 9:40 AM, "Jozsef Hegedus" <[email protected]> wrote:
Hi,

I have read (but probably not completely yet understood) Dhanji's book and
I don't know how to solve the following simple problem:

I have class A that uses(depends on) class B. B has no dependency.
Now I want to create
three different A objects : a1, a2 and a3;
and two different B objects : b1 and b2
in such a way that
1) a1 and a2 are injected with b1
2) a3 is injected with b2.

Any suggestions?

Cheers

Jozsef

--
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.
For more options, visit https://groups.google.com/groups/opt_out.
--
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.
For more options, visit https://groups.google.com/groups/opt_out.

--
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.
For more options, visit https://groups.google.com/groups/opt_out.

Reply via email to