You could inject the Injector into your method and call
Injector.injectMembers(bean);
On Dec 11, 2011 1:40 AM, "zonski" <[email protected]> wrote:
> If I bind my bean using either of the following:
>
> bind(MyInterface.class).to(MyInterfaceImpl.class);
>
> or
>
> bind(MyInterface.class).toInstance(new MyInterfaceImpl());
>
> The resulting bean will have all it's fields marked with @Inject
> automatically injected, just as I'd expect.
>
> However if I use an @Provides marked method to do exactly the same
> thing then my fields are not injected:
>
> // resulting bean is not injected?
> @Provides public MyInterface myInterface() {
> return new MyInterfaceImpl();
> }
>
> This seems a bit odd for me. I'm guessing this is done to allow
> developers to control the wiring for their provided classes, but in my
> case I don't want to control this, I just want to control how the bean
> gets instantiated (because in my real scenario I actually have to load
> my bean from an XML file) and have Guice still do all the autowiring.
>
> Is this really not possible?
>
> --
> 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.