I'm using Guice for the first time and find no convenient way to pass
an existing object as parameter of a constructor:

interface House {
    PowerSupply getPowerSupply();
    WaterSupply getWaterSupply();
    // More common utilities...
}

interface Lamp {
    void light();
}

class LampImpl implements Lamp {
    private final House house;

    public Lamp(House house) {
        this.house = house;
    }

    public void light() {
        PowerSupply power = house.getPowerSupply();
       // Light the lamp;
    }
}

class RoomImpl {
    private final House house;
    private Vector<Lamp> lamps;

    public Room(House house) {
        this.house = house;
    }

    void clean() {
        WaterSupply water = house.getWaterSupply();
        // clean the room
    }

    void addLamp() {
        Lamp lamp = new LampImpl(house);
        lamps.add(lamp);
    }
}

class Kitchen {
// Similar to Room
}

The idea is: we have rooms and kitchens and lamps who need common
utilities supplied by the containing house.

The question is: How do I apply Guice to create lamps inside a room?
How can I do something like: Lamp lamp =
injector.getInstance(Lamp.class, house) ?

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