There's a few things off with the code you pasted that may be throwing
assistedinject off.
The factory interface should just be:
* interface Factory {*
* Baz create(@Assisted("foo") Long p1, @Assisted("bar") Long p2);*
* }*
.. that is, no @Named(..) binding on the 'create' method.
Additionally, you added that you're expecting to have bindings like:
*
bind(Long.class).annotatedWith(Assisted.class).toInstance(System.nanoTime());
bind(Long.class).annotatedWith(Assisted.class).toInstance(4L); *
... but you actually _shouldn't_ have those bindings. AssistedInject
creates the assisted bindings for you automatically when you install the
module & call the factory methods.
Are you certain that TestowaRodzinaWładysława is injecting the factory (as
opposed to injecting the assisted object (Władysław) & calling create on
the factory? The error looks like what would happen if you attempted to
inject the assisted object directly.
sam
2012/1/2 koziolek <[email protected]>
> I have:
>
> public class Władysław implements Osoba {
>
> @Inject
> public Władysław(@Named("tata") Osoba tata, @Mama Osoba mama,
> @Assisted("dataUrodzenia") Long dataUrodzenia,
> @Assisted("liczbaRąk") Long liczbaRąk) {
> super();
> this.tata = tata;
> this.mama = mama;
> this.dataUrodzenia = dataUrodzenia;
> this.liczbaRąk = liczbaRąk;
> }
>
> }
>
> A factory
>
> public interface WładysławFactory {
>
> @Named("dataUrodzenia")
> public Władysław create(@Assisted("dataUrodzenia") Long
> dataUrodzenia,
> @Assisted("liczbaRąk") Long liczbaRąk);
>
> }
>
> And in module definition:
>
> install(new FactoryModuleBuilder().implement(Osoba.class,
>
> Władysław.class).build(WładysławFactory.class));
>
> But when I call:
>
> Władysław władysław = factory.create(System.nanoTime(),
> Random.nextLong(1, 10) );
>
> I get:
>
> 1) No implementation for java.lang.Long annotated with
> @com.google.inject.assistedinject.Assisted(value=dataUrodzenia) was
> bound.
> while locating java.lang.Long annotated with
> @com.google.inject.assistedinject.Assisted(value=dataUrodzenia)
> for parameter 2 at
> pl.koziolekweb.wjug.guice.base.Władysław.<init>(Władysław.java:26)
> at
>
> pl.koziolekweb.wjug.guice.base.TestowaRodzinaWładysława.configure(TestowaRodzinaWładysława.java:
> 14)
>
> 2) No implementation for java.lang.Long annotated with
> @com.google.inject.assistedinject.Assisted(value=liczbaRąk) was bound.
> while locating java.lang.Long annotated with
> @com.google.inject.assistedinject.Assisted(value=liczbaRąk)
> for parameter 3 at
> pl.koziolekweb.wjug.guice.base.Władysław.<init>(Władysław.java:26)
> at
>
> pl.koziolekweb.wjug.guice.base.TestowaRodzinaWładysława.configure(TestowaRodzinaWładysława.java:
> 14)
>
>
> I understand that i need to bindings like this:
>
>
> bind(Long.class).annotatedWith(Assisted.class).toInstance(System.nanoTime());
> bind(Long.class).annotatedWith(Assisted.class).toInstance(4L);
>
> but how can I put value to Assisted annotation? I'm looking somethong
> like Names but I didn't find.
>
> --
> You received this message because you are subscribed to the Google Groups
> "google-guice" group.
> To post to this group, send email to [email protected].
> To unsubscribe from this group, send email to
> [email protected].
> For more options, visit this group at
> http://groups.google.com/group/google-guice?hl=en.
>
>
--
You received this message because you are subscribed to the Google Groups
"google-guice" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/google-guice?hl=en.