I'll take a stab at this (though I'm a Guice n00b too! :-)...yes you can.
 I've done this using a provider in a custom module such as:

  @Provides
  protected Engine myEngineProvider(MyPart part1, MyPart part2, ...) {
    return new Engine(part1, part2, ...);
  }

where Guice injects needed parts into the @Provider method then you use
them to call the Engine() constructor directly.

If one of the parts is similarly not controlled by you, you can create
providers for them as well in a similar fashion.


On Fri, Nov 16, 2012 at 2:48 PM, Thomas <[email protected]> wrote:

> Hello,
>
> I'm new to Guice, and I have a constructor that I want to inject. However,
> one of the parameters for this constructor is from a class that is not in
> my control. Can I still use Guice to inject this constructor?
>
> Here is an example of what I'm talking about. In this case the Engine
> class is not in my control, but the parameters for the Engine object are in
> my control. If the Engine class was in my control I would just add @Inject
> to the constructor for the Engine class, but in my case I can't do that.
>
> public class Car {
>
>     private Engine engine;
>     private List<Wheel> wheels;
>
>     @Inject
>     public Car(Engine engine, List<Wheel> wheels) {
>         this.engine = engine;
>         this.wheels = wheels;
>     }
> }
>
> -Thomas
>
> --
> You received this message because you are subscribed to the Google Groups
> "google-guice" group.
> To view this discussion on the web visit
> https://groups.google.com/d/msg/google-guice/-/ONyOZzo67sMJ.
> 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.
>



-- 
Jeff Vincent
[email protected]
See my LinkedIn profile at:
http://www.linkedin.com/in/rjeffreyvincent
I ♥ DropBox <http://db.tt/9O6LfBX> !!

-- 
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.

Reply via email to