This is how it should be done (ref
<https://github.com/google/guice/wiki/AssistedInject>):
When you create A with assisted injection, you would need to also provide
an interface to create instance of A:
class A {
interface AFactory {
A create(String param)
}
public A(@Assisted String param) {... }
...
}
You would then bind the factory in your module:
install(new FactoryModuleBuilder()
.implement(A.class)
.build(AFactory.class));
In B, to create A, you should inject AFactory and NOT A:
class B {
private A a;
public B(AFactory factory) {
this.a = factory.create("param");
}
}
Thanks,
Tushar
On Wednesday, December 3, 2014 11:08:29 AM UTC+5:30, Guy Gadon wrote:
>
> I tried to avoid that, but I guess there is no choice.. It just that it
> feels like an overkill to create a factory that uses guice's factories in
> order to create a simple object.
>
> Thank you anyway :)
--
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/edca9f23-b5e6-4106-bb9e-7751919a9977%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.