I have this class:
public class House {
private final Door door;
private final Window window;
private final Roof roof;
@Inject
public House(
This is the way to go:
protected void configure() {
bind(Door.class);
bind(Window.class);
bind(Roof.class);
}
Since they are concrete classes, as Guice says, you can't bind them to themselves :-)
Check out the Binder docs, it notes:
bind(ServiceImpl.class);
This statement does essentially nothing; it "binds the
ServiceImpl
class to itself" and does not change Guice's default behavior. You may still want to use this if you prefer yourModule
class to serve as an explicit manifest for the services it provides. Also, in rare cases, Guice may be unable to validate a binding at injector creation time unless it is given explicitly.
Concrete classes with constructor marked as @Inject are automatically available for injection. But it helps the developer (you) know what is configured in the module.