我有这个类:
public class House {
private final Door door;
private final Window window;
private final Roof roof;
@Inject
public House(Door door, Window window, Roof roof) {
this.door = door;
this.window = window;
this.roof = roof;
}
}
假设 Door
、Window
和 Roof
是具体类。现在,如果我想要为这种情况实现一个Module,我将这样做:
public class HouseModule extends AbstractModule {
@Override
protected void configure() {
bind(Door.class).to(Door.class);
bind(Window.class).to(Window.class);
bind(Roof.class).to(Roof.class);
}
}
但我在想这是否是绑定具体类的正确方式,或者是否有更简单的方法。我感觉有更简单的方法。