I wish it was that simple :) This was of course a simplified version of my case. Even if you remove this A provider, but put some other bindings into the child injector it causes problems. For example if you bind another assisted factory which has assisted parameters of the same type as the parent assisted factory then you'll get a duplicate binding exception. For example if parent and child has String as assisted parameter then you'll get duplicated binding for String. Now I understand why this is, but if you don't know what is going on behind the scene it looks completely buggy.
I am not sure but I think if assisted factories create injector from private module it would solve those issues. On Jun 9, 8:43 pm, Sam Berlin <[email protected]> wrote: > FWIW, in this particular instance, it looks like you wouldn't even need to > provide the Provider binding, because of the fact that it's using child > injectors. With the prior version of the code, which didn't create a child > injector, you would need to wrap up your own child injector that bound > things explicitly. With the version of AssistedInject, when your AImpl is > constructed, it's using an internal child injector that already has A bound > to your AImpl the assistedinject factory created. > > So, so long as this is actually your problem (and it's not just a simpler > example for the sake of email), it looks like AssistedInject2 is actually > saving you code. :-) > > Sam > > On Tue, Jun 9, 2009 at 8:34 PM, [email protected] <[email protected]> wrote: > > > On Jun 9, 8:40 am, Dmitry Skavish <[email protected]> wrote: > > > 1) A binding to guice.test2.A was already configured at > > > guice.test2.AFactory.create(). > > > Gotcha. I'm actually glad that's it's a createChildInjector() thing. > > If it wasn't this, I had absolutely no idea what could be causing a > > duplicate bindings error! > > > The fix is crude, but it should work. In your AImpl constructor, just > > use "Injector.getParent()" rather than "Injector" to create a child > > off of. You want to create an injector that's a sibling of the throw- > > away injector uses by assisted inject. Alternatively, you could do > > assisted injection "by hand" by writing your own factory > > implementation (and not using FactoryProvider in a binding). > > > I gotta admit that injecting-the-injector was definitely not on my > > mind when we wrote this new feature; I'm sorry the API is clumsy for > > doing this! --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
